in computer-test/src/main/java/org/apache/hugegraph/computer/core/io/BufferedFileTest.java [104:151]
public void testWriteIntWithPosition() throws IOException {
File file = createTempFile();
try {
try (BufferedFileOutput output = createOutput(file)) {
for (int i = -128; i <= 127; i++) {
output.writeInt(i);
}
output.writeFixedInt(0, 1);
output.writeFixedInt(12, 2);
// Next buffer
output.writeFixedInt(200, 3);
// Previous buffer
output.writeFixedInt(100, 4);
output.writeInt(Integer.MAX_VALUE);
output.writeInt(Integer.MIN_VALUE);
// Current buffer
output.writeInt(5);
output.writeFixedInt(output.position() - Integer.BYTES, 6);
}
try (BufferedFileInput input = createInput(file)) {
for (int i = 0; i < 256; i++) {
int expectValue = i - 128;
int position = i * 4;
int readValue = input.readInt();
if (position != 0 && position != 12 &&
position != 200 && position != 100 &&
position != 1000) {
Assert.assertEquals(expectValue, readValue);
}
}
input.seek(0);
Assert.assertEquals(1, input.readInt());
input.seek(12);
Assert.assertEquals(2, input.readInt());
input.seek(200);
Assert.assertEquals(3, input.readInt());
input.seek(100);
Assert.assertEquals(4, input.readInt());
input.seek(256 * 4);
Assert.assertEquals(Integer.MAX_VALUE, input.readInt());
Assert.assertEquals(Integer.MIN_VALUE, input.readInt());
Assert.assertEquals(6, input.readInt());
}
} finally {
FileUtils.deleteQuietly(file);
}
}