Examples of DirectByteBufferOutputStream


Examples of org.apache.hama.bsp.message.io.DirectByteBufferOutputStream

    try {
      String fileName = System.getProperty("java.io.tmpdir")
          + File.separatorChar + "testSyncFlushByteBufferOutputStream.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());
      assertTrue(f.length() == 804);
      assertTrue(f.delete());
View Full Code Here

Examples of org.apache.hama.bsp.message.io.DirectByteBufferOutputStream

    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);

      for (int i = 0; i < 200; ++i) {
        intWritable.readFields(inStream);
        assertEquals(intWritable.get(), i);
      }

      intWritable.readFields(inStream);
      assertEquals(intWritable.get(), 199);

      try {
        intWritable.readFields(inStream);
        assertFalse(true);
      } catch (Exception e) {
        assertTrue(true);
      }

      inStream.close();
      syncFlushStream.close();

    } finally {
      if (f != null) {
        f.delete();
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.