@InterfaceAudience.Public @InterfaceStability.Evolving public class ByteBufferOutputStream extends OutputStream
Modifier and Type | Field and Description |
---|---|
protected ByteBuffer |
buf |
Constructor and Description |
---|
ByteBufferOutputStream(ByteBuffer bb) |
ByteBufferOutputStream(int capacity) |
ByteBufferOutputStream(int capacity,
boolean useDirectByteBuffer) |
Modifier and Type | Method and Description |
---|---|
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) |
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 buf
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()
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
IOException
public void writeInt(int i) throws IOException
int
to the underlying output stream as four
bytes, high byte first.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–2015 The Apache Software Foundation. All rights reserved.