Package org.apache.hadoop.hbase.io
Class ByteBufferOutputStream
java.lang.Object
java.io.OutputStream
org.apache.hadoop.hbase.io.ByteBufferOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,ByteBufferWriter
- Direct Known Subclasses:
ByteBufferListOutputStream
Not thread safe!
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionByteBufferOutputStream(int capacity) ByteBufferOutputStream(int capacity, boolean useDirectByteBuffer) -
Method Summary
Modifier and TypeMethodDescriptionprivate static ByteBufferallocate(int capacity, boolean useDirectByteBuffer) protected voidcheckSizeAndGrow(int extra) voidclose()voidflush()This flips the underlying BB so be sure to use it _last_!intsize()byte[]toByteArray(int offset, int length) voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) voidwrite(ByteBuffer b, int off, int len) Writeslenbytes from the specified ByteBuffer starting at offsetoffvoidwriteInt(int i) Writes anintto the underlying output stream as four bytes, high byte first.voidwriteTo(OutputStream out) Writes the complete contents of this byte buffer output stream to the specified output stream argument.
-
Field Details
-
MAX_ARRAY_SIZE
- See Also:
-
curBuf
-
-
Constructor Details
-
ByteBufferOutputStream
-
ByteBufferOutputStream
-
ByteBufferOutputStream
-
ByteBufferOutputStream
- Parameters:
bb- ByteBuffer to use. If too small, will be discarded and a new one allocated in its place; i.e. the passed in BB may NOT BE RETURNED!! Minimally it will be altered. SIDE EFFECT!! If you want to get the newly allocated ByteBuffer, you'll need to pick it up when done with this instance by callinggetByteBuffer(). All this encapsulation violation is so we can recycle buffers rather than allocate each time; it can get expensive especially if the buffers are big doing allocations each time or having them undergo resizing because initial allocation was small.- See Also:
-
-
Method Details
-
size
-
allocate
-
getByteBuffer
This flips the underlying BB so be sure to use it _last_! -
checkSizeAndGrow
-
write
- Specified by:
writein classOutputStream- Throws:
IOException
-
writeTo
Writes the complete contents of this byte buffer output stream to the specified output stream argument.- Parameters:
out- the output stream to which to write the data.- Throws:
IOException- if an I/O error occurs.
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classOutputStream- Throws:
IOException
-
write
Description copied from interface:ByteBufferWriterWriteslenbytes from the specified ByteBuffer starting at offsetoff- Specified by:
writein interfaceByteBufferWriter- 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.
-
writeInt
Writes anintto the underlying output stream as four bytes, high byte first.- Specified by:
writeIntin interfaceByteBufferWriter- Parameters:
i- theintto write- Throws:
IOException- if an I/O error occurs.
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
toByteArray
-