public class GSByteArrayOutputStream extends OutputStream
Modifier and Type | Field and Description |
---|---|
protected byte[] |
_buffer
The buffer where data is stored.
|
protected int |
_count
The number of valid bytes in the buffer.
|
Constructor and Description |
---|
GSByteArrayOutputStream()
Creates a new byte array output stream.
|
GSByteArrayOutputStream(int capacity)
Creates a new byte array output stream, with a buffer capacity of the specified size, in
bytes.
|
Modifier and Type | Method and Description |
---|---|
void |
copyToBuffer(ByteBuffer buffer)
Copy internal buffer
|
boolean |
ensureCapacity(int delta) |
byte[] |
getBuffer()
Gets internal buffers
|
int |
getCapacity()
The current buffer capacity.
|
byte[] |
getCompactBuffer()
Gets the underlying buffer if its size is at most two times more than the actual data written
on the buffer.
|
int |
getCount()
get buffer count
|
void |
reset()
Resets the
count field of this byte array output stream to zero, so that all
currently accumulated output in the output stream is discarded. |
void |
setBuffer(byte[] buf)
Set stream buffer, and reset the counter.
|
void |
setBuffer(byte[] buffer,
int count)
Set stream buffer and set the counter.
|
void |
setSize(int size)
Set the buffer size.
|
int |
size()
Returns the current size of the buffer.
|
byte[] |
toByteArray()
Creates a newly allocated byte array.
|
void |
write(byte[] b,
int off,
int len)
Writes
len bytes from the specified byte array starting at offset
off to this byte array output stream. |
void |
write(int b)
Writes the specified byte to this byte array output stream.
|
void |
writeByte(byte b) |
void |
writeByte(byte v,
int position)
Writes the provided value at the specified position.
|
void |
writeInt(int v,
int position)
Writes the provided value at the specified position.
|
void |
writeShort(short v,
int position)
Writes the provided value at the specified position.
|
void |
writeTo(OutputStream out)
Writes the complete contents of this byte array output stream to the specified output stream
argument, as if by calling the output stream's write method using
out.write(buf, 0,
count) . |
close, flush, write
protected byte[] _buffer
protected int _count
public GSByteArrayOutputStream()
public GSByteArrayOutputStream(int capacity)
capacity
- the initial capacity.IllegalArgumentException
- if size is negative.public final void copyToBuffer(ByteBuffer buffer)
arr
- target buffersrcPos
- start positionpublic void setBuffer(byte[] buf)
buf
- new bufferpublic void setBuffer(byte[] buffer, int count)
buf
- new buffercount
- amount of valid bytespublic byte[] getBuffer()
public int getCount()
public void setSize(int size)
size
- amount of valid bytespublic int size()
count
field, which is the number of valid bytes in this
output stream.ByteArrayOutputStream.count
public int getCapacity()
public void write(int b)
write
in class OutputStream
b
- the byte to be written.public void writeByte(byte b)
public void writeByte(byte v, int position)
public void writeShort(short v, int position)
public void writeInt(int v, int position)
public void write(byte[] b, int off, int len)
len
bytes from the specified byte array starting at offset
off
to this byte array output stream.write
in class OutputStream
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.public boolean ensureCapacity(int delta)
public void writeTo(OutputStream out) throws IOException
out.write(buf, 0,
count)
.out
- the output stream to which to write the data.IOException
- if an I/O error occurs.public void reset()
count
field of this byte array output stream to zero, so that all
currently accumulated output in the output stream is discarded. The output stream can be used
again, reusing the already allocated buffer space.ByteArrayInputStream.count
public byte[] toByteArray()
ByteArrayOutputStream.size()
public byte[] getCompactBuffer()
Copyright © GigaSpaces.