use of org.neo4j.io.fs.PhysicalFlushableChecksumChannel in project neo4j by neo4j.
the class PhysicalFlushableChecksumChannelTest method calculateChecksum.
@Test
void calculateChecksum() throws IOException {
final Path firstFile = directory.homePath().resolve("file1");
StoreChannel storeChannel = fileSystem.write(firstFile);
int channelChecksum;
try (PhysicalFlushableChecksumChannel channel = new PhysicalFlushableChecksumChannel(storeChannel, new HeapScopedBuffer(100, INSTANCE))) {
channel.beginChecksum();
channel.put((byte) 10);
channelChecksum = channel.putChecksum();
}
int fileSize = (int) fileSystem.getFileSize(firstFile);
assertEquals(Byte.BYTES + Integer.BYTES, fileSize);
byte[] writtenBytes = new byte[fileSize];
try (InputStream in = Files.newInputStream(firstFile)) {
in.read(writtenBytes);
}
ByteBuffer buffer = ByteBuffer.wrap(writtenBytes);
Checksum checksum = CHECKSUM_FACTORY.get();
checksum.update(10);
assertEquals(checksum.getValue(), channelChecksum);
assertEquals(10, buffer.get());
assertEquals(checksum.getValue(), buffer.getInt());
}
Aggregations