System.out.println("NTFS : Test sparse file (" + TEST_IMAGE_FILENAME_2 + ").");
try {
File file = new File(TEST_IMAGE_FILENAME_2);
Device device = new FileDevice(file, "r");
FileSystem<?> fileSystem = new NTFSFileSystemType().create(device, true);
FSDirectory root = fileSystem.getRootEntry().getDirectory();
// The first file has 256 bytes of real data at the front, and the rest is sparse.
byte[] expectedContents = new byte[10240];
for (int i = 0; i < 256; i++) {
expectedContents[i] = (byte) i;
}
FSFile sparseFile1 = root.getEntry("sparsefile1.dat").getFile();
assertEquals("Wrong length for sparse file 2", expectedContents.length, sparseFile1.getLength());
byte[] actualContents = new byte[expectedContents.length];
sparseFile1.read(0, ByteBuffer.wrap(actualContents));
Arrays.fill(actualContents, 256, 4096, (byte) 0); // slack space contains garbage, so wipe it.
assertEquals("Wrong contents for sparse file 1", expectedContents, actualContents);
// The second file is 100% sparse.
expectedContents = new byte[10240];
FSFile sparseFile2 = root.getEntry("sparsefile2.dat").getFile();
assertEquals("Wrong length for sparse file 2", expectedContents.length, sparseFile2.getLength());
actualContents = new byte[expectedContents.length];
sparseFile2.read(0, ByteBuffer.wrap(actualContents));
assertEquals("Wrong contents for sparse file 2", expectedContents, actualContents);
fileSystem.close();