@InterfaceAudience.Public public class ByteBufferOutputStream extends OutputStream implements ByteBufferWriter
Modifier and Type | Field and Description |
---|---|
protected ByteBuffer |
curBuf |
Constructor and Description |
---|
ByteBufferOutputStream(ByteBuffer bb) |
ByteBufferOutputStream(int capacity) |
ByteBufferOutputStream(int capacity,
boolean useDirectByteBuffer) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkSizeAndGrow(int extra) |
void |
close() |
void |
flush() |
ByteBuffer |
getByteBuffer()
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(ByteBuffer b,
int off,
int len)
Writes
len bytes from the specified ByteBuffer starting at offset off |
void |
write(int b) |
void |
writeInt(int i)
Writes an
int 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.
|
protected ByteBuffer curBuf
public ByteBufferOutputStream(int capacity)
public ByteBufferOutputStream(int capacity, boolean useDirectByteBuffer)
public ByteBufferOutputStream(ByteBuffer bb)
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 calling getByteBuffer()
. 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.getByteBuffer()
public int size()
public ByteBuffer getByteBuffer()
protected void checkSizeAndGrow(int extra)
public void write(int b) throws IOException
write
in class OutputStream
IOException
public void writeTo(OutputStream out) throws IOException
out
- the output stream to which to write the data.IOException
- if an I/O error occurs.public void write(byte[] b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
IOException
public void write(ByteBuffer b, int off, int len) throws IOException
ByteBufferWriter
len
bytes from the specified ByteBuffer starting at offset off
write
in interface ByteBufferWriter
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.IOException
- if an I/O error occurs.public void writeInt(int i) throws IOException
int
to the underlying output stream as four
bytes, high byte first.writeInt
in interface ByteBufferWriter
i
- the int
to writeIOException
- if an I/O error occurs.public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
public byte[] toByteArray(int offset, int length)
Copyright © 2007–2019 Cloudera. All rights reserved.