public void testSyncFlushBufferInputStream() throws Exception {
File f = null;
try {
String fileName = System.getProperty("java.io.tmpdir")
+ File.separatorChar + "testSyncFlushBufferInputStream.txt";
SyncFlushByteBufferOutputStream stream = new SyncFlushByteBufferOutputStream(
fileName);
DirectByteBufferOutputStream syncFlushStream = new DirectByteBufferOutputStream(
stream);
ByteBuffer buffer = ByteBuffer.allocateDirect(512);
syncFlushStream.setBuffer(buffer);
IntWritable intWritable = new IntWritable(1);
for (int i = 0; i < 200; ++i) {
intWritable.set(i);
intWritable.write(syncFlushStream);
}
intWritable.write(syncFlushStream);
syncFlushStream.close();
f = new File(fileName);
assertTrue(f.exists());
assertEquals(f.length(), 804);
SyncReadByteBufferInputStream syncReadStream = new SyncReadByteBufferInputStream(
stream.isSpilled(), fileName);
DirectByteBufferInputStream inStream = new DirectByteBufferInputStream(
syncReadStream);
buffer.clear();
inStream.setBuffer(buffer);