public class ByteBufferOutputStream extends OutputStream
OutputStream around a
ByteBuffer.| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUF_SIZE |
static boolean |
DEFAULT_CAN_GROW |
| Constructor and Description |
|---|
ByteBufferOutputStream()
Create a new object with the
DEFAULT_BUF_SIZE buffer size and it
can grow. |
ByteBufferOutputStream(byte[] aArray)
Constructor with an existing byte array to wrap.
|
ByteBufferOutputStream(byte[] aArray,
int nOfs,
int nLen)
Constructor with an existing byte array to wrap.
|
ByteBufferOutputStream(ByteBuffer aBuffer,
boolean bCanGrow)
Constructor
|
ByteBufferOutputStream(int nBytes)
Constructor for an output stream than can grow.
|
ByteBufferOutputStream(int nBytes,
boolean bCanGrow)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canGrow() |
void |
close() |
byte[] |
getAsByteArray()
Get everything as a big byte array, without altering the ByteBuffer.
|
String |
getAsString(Charset aCharset)
Get the content as a string without modifying the buffer
|
ByteBuffer |
getBuffer() |
void |
reset()
Reset the backing byte buffer
|
int |
size() |
void |
write(byte[] aBuf,
int nOfs,
int nLen) |
void |
write(ByteBuffer aSrcBuffer)
Write the content from the passed byte buffer to this output stream.
|
void |
write(int b) |
void |
writeTo(byte[] aBuf)
Writes the current content to the passed buffer.
|
void |
writeTo(byte[] aBuf,
int nOfs,
int nLen)
Write current content to the passed byte array.
|
void |
writeTo(ByteBuffer aDestBuffer)
Write everything currently contained to the specified buffer.
|
void |
writeTo(OutputStream aOS)
Write everything to the passed output stream and clear the contained
buffer.
|
flush, writepublic static final int DEFAULT_BUF_SIZE
public static final boolean DEFAULT_CAN_GROW
public ByteBufferOutputStream()
DEFAULT_BUF_SIZE buffer size and it
can grow.public ByteBufferOutputStream(@Nonnegative int nBytes)
nBytes - The initial number of bytes the buffer has. Must be ≥ 0.public ByteBufferOutputStream(@Nonnegative int nBytes, boolean bCanGrow)
nBytes - The number of bytes the buffer has initially. Must be ≥ 0.bCanGrow - true if the buffer can grow, false
otherwise.public ByteBufferOutputStream(@Nonnull byte[] aArray)
aArray - The array to be backed by a ByteBuffer.public ByteBufferOutputStream(@Nonnull byte[] aArray, @Nonnegative int nOfs, @Nonnegative int nLen)
aArray - The array to be backed by a ByteBuffer.nOfs - Offset into the byte array. Must be ≥ 0.nLen - Number of bytes to wrap. Must be ≥ 0.public ByteBufferOutputStream(@Nonnull ByteBuffer aBuffer, boolean bCanGrow)
aBuffer - The byte buffer to use. May not be null.bCanGrow - true if the buffer can grow, false
otherwise.@Nonnull public ByteBuffer getBuffer()
null.public boolean canGrow()
true if this buffer can grow, false if
not.public void close()
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreampublic void reset()
@Nonnegative public int size()
@Nonnull @ReturnsMutableCopy public byte[] getAsByteArray()
null.public void writeTo(@Nonnull ByteBuffer aDestBuffer)
BufferOverflowException is thrown.
The copied elements are removed from this streams buffer.aDestBuffer - The destination buffer to write to. May not be null.public void writeTo(@Nonnull byte[] aBuf)
aBuf - The buffer to be filled. May not be null.public void writeTo(@Nonnull byte[] aBuf, @Nonnegative int nOfs, @Nonnegative int nLen)
aBuf - Byte array to write to. May not be null.nOfs - Offset to start writing. Must be ≥ 0.nLen - Number of bytes to copy. Must be ≥ 0.public void writeTo(@Nonnull @WillNotClose OutputStream aOS) throws IOException
aOS - The output stream to write to. May not be null.IOException - In case of IO error@Nonnull public String getAsString(@Nonnull Charset aCharset)
aCharset - The charset to use. May not be null.public void write(int b)
write in class OutputStreampublic void write(@Nonnull byte[] aBuf, @Nonnegative int nOfs, @Nonnegative int nLen)
write in class OutputStreampublic void write(@Nonnull ByteBuffer aSrcBuffer)
aSrcBuffer - The buffer to use. May not be null.Copyright © 2014–2016 Philip Helger. All rights reserved.