public void testWritableChannelAppend() throws Exception { writeToFile("/append.txt", "Initial text.", 3); WritableGridFileChannel channel = fs.getWritableChannel("/append.txt", true); try { channel.write(ByteBuffer.wrap("Appended text.".getBytes())); } finally { channel.close(); } assertEquals(getContents("/append.txt"), "Initial text.Appended text."); }
public void testWritableChannel() throws Exception { WritableGridFileChannel channel = fs.getWritableChannel("/channelTest.txt", false, 10); try { assertTrue(channel.isOpen()); channel.write(ByteBuffer.wrap("This file spans multiple chunks.".getBytes())); } finally { channel.close(); } assertFalse(channel.isOpen()); assertEquals(getContents("/channelTest.txt"), "This file spans multiple chunks."); }
public void testReadLoop() throws Exception { WritableGridFileChannel wgfc = fs.getWritableChannel("/readTest.txt", false, 100); try { assertTrue(wgfc.isOpen()); wgfc.write(ByteBuffer.wrap("This tests read loop.".getBytes())); } finally { wgfc.close(); } ReadableGridFileChannel rgfc = fs.getReadableChannel("/readTest.txt"); try { assertTrue( "This tests read loop.".equals(new String(toBytes(Channels.newInputStream(rgfc))))); } finally { rgfc.close(); } }