}
}
public static void copyDevice(Device imageDevice, Device workDevice)
throws ApiNotFoundException, IOException {
BlockDeviceAPI imgApi = imageDevice.getAPI(BlockDeviceAPI.class);
BlockDeviceAPI wrkApi = workDevice.getAPI(BlockDeviceAPI.class);
if (imgApi.getLength() != wrkApi.getLength())
throw new IllegalArgumentException("devices of different length");
// if(imgApi.getSectorSize() != wrkApi.getSectorSize())
// throw new IllegalArgumentException("devices of different sector
// size");
// int sectorSize = imgApi.getSectorSize();
int sectorSize = 512;
byte[] sector = new byte[sectorSize];
long nbSectors = imgApi.getLength() / sectorSize;
long devOffset = 0;
for (int s = 0; s < nbSectors; s++) {
// log.debug("copying sector "+s);
imgApi.read(devOffset, ByteBuffer.wrap(sector, 0, sector.length));
wrkApi.write(devOffset, ByteBuffer.wrap(sector, 0, sector.length));
devOffset += sectorSize;
}
}