public class FixedByteArrayOutputStream
extends java.io.OutputStream
ByteArrayOutptStream, that provides access to the internal buffer for efficiency.| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
The buffer to contains the bytes written to this stream.
|
protected int |
count
The number of bytes written to this stream.
|
| Constructor and Description |
|---|
FixedByteArrayOutputStream(byte[] buf)
Creates a
FixedByteArrayOutputStream using the given buffer. |
FixedByteArrayOutputStream(int size)
Creates a
FixedByteArrayOutputStream with a newly allocated buffer of the given size. |
| Modifier and Type | Method and Description |
|---|---|
int |
bufSize()
Returns the capacity of the internal buffer.
|
void |
close()
Closes this output stream.
|
byte[] |
getBytes()
Returns a reference to the full internal buffer.
|
void |
reset()
Resets the count of bytes written to this stream to zero.
|
int |
size()
Returns the number of bytes written to this stream.
|
byte[] |
toByteArray()
Returns a newly allocated byte array of size equal to the number of valid bytes written to this stream.
|
void |
write(byte[] b) |
void |
write(byte[] b, int off, int len) |
void |
write(int b) |
protected byte[] buf
protected int count
public FixedByteArrayOutputStream(int size)
FixedByteArrayOutputStream with a newly allocated buffer of the given size.public FixedByteArrayOutputStream(byte[] buf)
FixedByteArrayOutputStream using the given buffer. The initial contents of buf, if any, will be ignored.
public void close()
throws java.io.IOException
write methods after close will cause an exception to be thrown.close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.OutputStreamjava.io.IOExceptionpublic void reset()
public int size()
public int bufSize()
public byte[] toByteArray()
public byte[] getBytes()
IllegalStateException is thrown.
public void write(byte[] b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOException
public void write(byte[] b,
int off,
int len)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOException
public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOException