Package org.apache.hadoop.hbase.io
Class ByteBufferListOutputStream
java.lang.Object
java.io.OutputStream
org.apache.hadoop.hbase.io.ByteBufferOutputStream
org.apache.hadoop.hbase.io.ByteBufferListOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,ByteBufferWriter
An OutputStream which writes data into ByteBuffers. It will try to get ByteBuffer, as and when
needed, from the passed pool. When pool is not giving a ByteBuffer it will create one on heap.
Make sure to call
releaseResources()
method once the Stream usage is over and data is
transferred to the wanted destination. Not thread safe!-
Field Summary
Modifier and TypeFieldDescriptionprotected List<SingleByteBuff>
private final ByteBuffAllocator
private boolean
private static final org.slf4j.Logger
Fields inherited from class org.apache.hadoop.hbase.io.ByteBufferOutputStream
curBuf
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
protected void
checkSizeAndGrow
(int extra) This flips the underlying BB so be sure to use it _last_!We can be assured that the buffers returned by this method are all flippedvoid
Release the resources it uses (The ByteBuffers) which are obtained from pool.int
size()
byte[]
toByteArray
(int offset, int length) void
write
(byte[] b, int off, int len) void
write
(ByteBuffer b, int off, int len) Writeslen
bytes from the specified ByteBuffer starting at offsetoff
void
writeTo
(OutputStream out) Writes the complete contents of this byte buffer output stream to the specified output stream argument.
-
Field Details
-
LOG
-
allocator
-
allBufs
-
lastBufFlipped
-
-
Constructor Details
-
ByteBufferListOutputStream
-
-
Method Details
-
allocateNewBuffer
-
size
- Overrides:
size
in classByteBufferOutputStream
-
getByteBuffer
Description copied from class:ByteBufferOutputStream
This flips the underlying BB so be sure to use it _last_!- Overrides:
getByteBuffer
in classByteBufferOutputStream
-
checkSizeAndGrow
- Overrides:
checkSizeAndGrow
in classByteBufferOutputStream
-
writeTo
Description copied from class:ByteBufferOutputStream
Writes the complete contents of this byte buffer output stream to the specified output stream argument.- Overrides:
writeTo
in classByteBufferOutputStream
- Parameters:
out
- the output stream to which to write the data.- Throws:
IOException
- if an I/O error occurs.
-
releaseResources
Release the resources it uses (The ByteBuffers) which are obtained from pool. Call this only when all the data is fully used. And it must be called at the end of usage else we will leak ByteBuffers from pool. -
toByteArray
- Overrides:
toByteArray
in classByteBufferOutputStream
-
getByteBuffers
We can be assured that the buffers returned by this method are all flipped- Returns:
- list of bytebuffers
-
write
- Overrides:
write
in classByteBufferOutputStream
- Throws:
IOException
-
write
Description copied from interface:ByteBufferWriter
Writeslen
bytes from the specified ByteBuffer starting at offsetoff
- Specified by:
write
in interfaceByteBufferWriter
- Overrides:
write
in classByteBufferOutputStream
- Parameters:
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.- Throws:
IOException
- if an I/O error occurs.
-