Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Last active June 23, 2020 14:40
public void restoreDisk() {
RaidDisk disk1 = new RaidDisk(2);
disk1.set(0, MoreInts.toByte("01101101"));
disk1.set(1, MoreInts.toByte("00101101"));
RaidDisk disk2 = new RaidDisk(1);
disk2.set(0, MoreInts.toByte("11010100"));
RaidDisk raidDisk = disk1.xor(disk2); // This xor allow to keep data for both disk in RaidDisk
RaidDisk newDisk1 = raidDisk.xor(disk2); // If we loose disk1 then disk1 can be restore using raidDisk ^ disk2
RaidDisk newDisk2 = raidDisk.xor(disk1);
assertEquals(disk1.toBinary(), newDisk1.toBinary());
assertEquals(disk2.toBinary(), newDisk2.toBinary());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment