rabbit.io
Class SimpleBufferHandle

java.lang.Object
  extended by rabbit.io.SimpleBufferHandle
All Implemented Interfaces:
BufferHandle

public class SimpleBufferHandle
extends Object
implements BufferHandle

A handle to a ByteBuffer.

Author:
Robert Olofsson

Constructor Summary
SimpleBufferHandle(ByteBuffer buffer)
          Create a BufferHandle that wraps the given ByteBuffer.
 
Method Summary
 ByteBuffer getBuffer()
          Get a byte buffer of reasonable size, the buffer will have been cleared.
 ByteBuffer getLargeBuffer()
          Get a byte buffer of reasonable size, the buffer will have been cleared.
 boolean isEmpty()
          Check if this handle is empty, that is if no buffer exists or the buffer is empty.
 boolean isLarge(ByteBuffer buffer)
          Check if the given buffer is a large buffer
 void possiblyFlush()
          release a buffer if possible.
 void setMayBeFlushed(boolean mayBeFlushed)
          Flag that the internal ByteBuffer may not be flushed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleBufferHandle

public SimpleBufferHandle(ByteBuffer buffer)
Create a BufferHandle that wraps the given ByteBuffer.

Parameters:
buffer - the ByteBuffer to wrap
Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: BufferHandle
Check if this handle is empty, that is if no buffer exists or the buffer is empty.

Specified by:
isEmpty in interface BufferHandle
Returns:
true if the buffer currently is empty

getBuffer

public ByteBuffer getBuffer()
Description copied from interface: BufferHandle
Get a byte buffer of reasonable size, the buffer will have been cleared.

Specified by:
getBuffer in interface BufferHandle
Returns:
the actual ByteBuffer

getLargeBuffer

public ByteBuffer getLargeBuffer()
Description copied from interface: BufferHandle
Get a byte buffer of reasonable size, the buffer will have been cleared.

Specified by:
getLargeBuffer in interface BufferHandle
Returns:
the large buffer to use

isLarge

public boolean isLarge(ByteBuffer buffer)
Description copied from interface: BufferHandle
Check if the given buffer is a large buffer

Specified by:
isLarge in interface BufferHandle
Parameters:
buffer - the ByteBuffer to check
Returns:
true if the given buffer is large

possiblyFlush

public void possiblyFlush()
Description copied from interface: BufferHandle
release a buffer if possible.

Specified by:
possiblyFlush in interface BufferHandle

setMayBeFlushed

public void setMayBeFlushed(boolean mayBeFlushed)
Description copied from interface: BufferHandle
Flag that the internal ByteBuffer may not be flushed.

Specified by:
setMayBeFlushed in interface BufferHandle
Parameters:
mayBeFlushed - if true the buffer may be returned, if false the putBuffer call will throw an exception