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
FieldsModifier and TypeFieldDescriptionprotected List<SingleByteBuff>private final ByteBuffAllocatorprivate booleanprivate static final org.slf4j.LoggerFields inherited from class org.apache.hadoop.hbase.io.ByteBufferOutputStream
curBuf -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprotected voidcheckSizeAndGrow(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 flippedvoidRelease the resources it uses (The ByteBuffers) which are obtained from pool.intsize()byte[]toByteArray(int offset, int length) voidwrite(byte[] b, int off, int len) voidwrite(ByteBuffer b, int off, int len) Writeslenbytes from the specified ByteBuffer starting at offsetoffvoidwriteTo(OutputStream out) Writes the complete contents of this byte buffer output stream to the specified output stream argument.Methods inherited from class org.apache.hadoop.hbase.io.ByteBufferOutputStream
close, flush, write, write, writeIntMethods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
LOG
-
allocator
-
allBufs
-
lastBufFlipped
-
-
Constructor Details
-
ByteBufferListOutputStream
-
-
Method Details
-
allocateNewBuffer
-
size
- Overrides:
sizein classByteBufferOutputStream
-
getByteBuffer
Description copied from class:ByteBufferOutputStreamThis flips the underlying BB so be sure to use it _last_!- Overrides:
getByteBufferin classByteBufferOutputStream
-
checkSizeAndGrow
- Overrides:
checkSizeAndGrowin classByteBufferOutputStream
-
writeTo
Description copied from class:ByteBufferOutputStreamWrites the complete contents of this byte buffer output stream to the specified output stream argument.- Overrides:
writeToin 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:
toByteArrayin classByteBufferOutputStream
-
getByteBuffers
We can be assured that the buffers returned by this method are all flipped- Returns:
- list of bytebuffers
-
write
- Overrides:
writein classByteBufferOutputStream- Throws:
IOException
-
write
Description copied from interface:ByteBufferWriterWriteslenbytes from the specified ByteBuffer starting at offsetoff- Specified by:
writein interfaceByteBufferWriter- Overrides:
writein 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.
-