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
-
Constructor Summary
ConstructorDescriptionByteBufferOutputStream
(int capacity) ByteBufferOutputStream
(int capacity, boolean useDirectByteBuffer) -
Method Summary
Modifier and TypeMethodDescriptionprivate static ByteBuffer
allocate
(int capacity, boolean useDirectByteBuffer) protected void
checkSizeAndGrow
(int extra) void
close()
void
flush()
This flips the underlying BB so be sure to use it _last_!int
size()
byte[]
toByteArray
(int offset, int length) void
write
(byte[] b) void
write
(byte[] b, int off, int len) void
write
(int b) void
write
(ByteBuffer b, int off, int len) Writeslen
bytes from the specified ByteBuffer starting at offsetoff
void
writeInt
(int i) Writes anint
to the underlying output stream as four bytes, high byte first.void
writeTo
(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:
write
in 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:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
Description copied from interface:ByteBufferWriter
Writeslen
bytes from the specified ByteBuffer starting at offsetoff
- Specified by:
write
in 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 anint
to the underlying output stream as four bytes, high byte first.- Specified by:
writeInt
in interfaceByteBufferWriter
- Parameters:
i
- theint
to write- Throws:
IOException
- if an I/O error occurs.
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
toByteArray
-