Java Code Examples for org.apache.hadoop.io.ByteBufferPool#putBuffer()

The following examples show how to use org.apache.hadoop.io.ByteBufferPool#putBuffer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FSDataInputStream.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void releaseBuffer(ByteBuffer buffer) {
  try {
    ((HasEnhancedByteBufferAccess)in).releaseBuffer(buffer);
  }
  catch (ClassCastException e) {
    ByteBufferPool bufferPool = extendedReadBuffers.remove( buffer);
    if (bufferPool == null) {
      throw new IllegalArgumentException("tried to release a buffer " +
          "that was not created by this stream.");
    }
    bufferPool.putBuffer(buffer);
  }
}
 
Example 2
Source File: TestByteBufferUtil.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void testReadHelper(final int readSize, final int readLimit) throws Exception {
  ByteArrayInputStream inputStream = new LimitedByteArrayInputStream(testData, readLimit);
  ByteBufferPool adapterPool = new TestByteBufferPool();
  int currOffset = 0;
  while (currOffset < TEST_DATA_SIZE) {
    ByteBuffer byteBuffer = ByteBufferUtil.fallbackRead(inputStream, adapterPool, readSize);
    final int length = byteBuffer.remaining();
    for (int i = 0; i < length; i++) {
      assertEquals(testData[currOffset + i], byteBuffer.get());
    }
    adapterPool.putBuffer(byteBuffer);
    currOffset += length;
  }
}
 
Example 3
Source File: FSDataInputStream.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void releaseBuffer(ByteBuffer buffer) {
  try {
    ((HasEnhancedByteBufferAccess)in).releaseBuffer(buffer);
  }
  catch (ClassCastException e) {
    ByteBufferPool bufferPool = extendedReadBuffers.remove( buffer);
    if (bufferPool == null) {
      throw new IllegalArgumentException("tried to release a buffer " +
          "that was not created by this stream.");
    }
    bufferPool.putBuffer(buffer);
  }
}