示例#1
0
  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.");
  }
示例#2
0
 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.");
 }
示例#3
0
 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();
   }
 }