public class ByteArrayOutput extends BufferedOutput
BufferedOutput
using single byte array buffer.buffer, EMPTY_BYTE_ARRAY, limit, position
Constructor and Description |
---|
ByteArrayOutput()
Creates a new byte array output without pre-allocated buffer.
|
ByteArrayOutput(byte[] buffer)
Creates a new byte array output with the specified buffer.
|
ByteArrayOutput(int size)
Creates a new byte array output with the specified buffer capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears this buffer.
|
void |
ensureCapacity(int requiredCapacity)
Ensures that the byte array used for buffering has at least the specified capacity.
|
byte[] |
getBuffer()
Returns byte array used for buffering.
|
int |
getLimit()
Returns limit.
|
int |
getPosition()
Returns position.
|
protected void |
needSpace()
This method is invoked when output methods need more space to write data.
|
void |
setBuffer(byte[] newBuffer)
Sets specified byte array to be used for buffering.
|
void |
setLimit(int newLimit)
Sets limit as specified.
|
void |
setPosition(int newPosition)
Sets position as specified.
|
byte[] |
toByteArray()
Returns a full copy of byte array buffer from zero to the position.
|
String |
toString()
Converts the buffer's content from zero to the position into a string,
translating bytes into characters according to the platform's default character encoding.
|
write, write, write, writeBoolean, writeByte, writeByteArray, writeBytes, writeChar, writeChars, writeCompactInt, writeCompactLong, writeDouble, writeFloat, writeInt, writeLong, writeObject, writeShort, writeUTF, writeUTFChar, writeUTFString
close, flush
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
close, flush
public ByteArrayOutput()
public ByteArrayOutput(int size)
size
- the initial buffer sizeIllegalArgumentException
- if size is negativepublic ByteArrayOutput(byte[] buffer)
buffer
- the buffer.NullPointerException
- if the buffer is null.protected void needSpace() throws IOException
BufferedOutput
(position < limit)
is true or throw an exception. This method may block if needed.
This method is allowed to update buffer, position and limit fields as needed.needSpace
in class BufferedOutput
IOException
- if an I/O error occurspublic byte[] getBuffer()
public void setBuffer(byte[] newBuffer)
public int getPosition()
public void setPosition(int newPosition)
IllegalArgumentException
- if the new position is negative or is larger than the limitpublic int getLimit()
public void setLimit(int newLimit)
IllegalArgumentException
- if the new limit is negative or is larger than the capacitypublic void clear()
public void ensureCapacity(int requiredCapacity)
public byte[] toByteArray()
Copyright © 2014 Devexperts. All Rights Reserved.