@Mutable @ThreadSafety(level=NOT_THREADSAFE) public final class FixedArrayOutputStream extends java.io.OutputStream implements java.io.Serializable
OutputStream
implementation that writes data
to a provided byte array. It is similar to the
java.io.ByteArrayOutputStream
class, except that it allows you to
pass in the array that it uses, and the array will not grow over time.Constructor and Description |
---|
FixedArrayOutputStream(byte[] array)
Creates a new output stream that will write data to the provided array.
|
FixedArrayOutputStream(byte[] array,
int pos,
int len)
Creates a new output stream that will write data to the provided array.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this output stream.
|
void |
flush()
Flushes this output stream.
|
byte[] |
getBackingArray()
Retrieves the backing array used by this output stream.
|
int |
getBytesWritten()
Retrieves the number of bytes that have been written so far to this output
stream.
|
int |
getInitialPosition()
Retrieves the initial position provided when this output stream was
created.
|
int |
getLength()
Retrieves the maximum number of bytes that may be written to this output
stream.
|
void |
write(byte[] b)
Writes the contents of the provided array to this output stream.
|
void |
write(byte[] b,
int off,
int len)
Writes the contents of the provided array to this output stream.
|
void |
write(int b)
Writes the provided byte to this output stream.
|
public FixedArrayOutputStream(@NotNull byte[] array)
array
- The array to which data will be written. It must not be
null
.public FixedArrayOutputStream(@NotNull byte[] array, int pos, int len)
array
- The array to which data will be written. It must not be
null
.pos
- The position at which to start writing data. It must be
greater than or equal to zero and less than or equal to the
length of the array.len
- The maximum number of bytes that may be written. It must
be greater than or equal to zero and less than or equal to
the difference between the length of the array and the
provided pos
value.@NotNull public byte[] getBackingArray()
public int getInitialPosition()
public int getLength()
public int getBytesWritten()
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
public void flush()
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
b
- The byte to be written.java.io.IOException
- If an attempt was made to write beyond the end of the
array.public void write(@NotNull byte[] b) throws java.io.IOException
write
in class java.io.OutputStream
b
- The byte array containing the data to be written. It must not
be null
.java.io.IOException
- If an attempt was made to write beyond the end of the
array.public void write(@NotNull byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
b
- The byte array containing the data to be written. It must not
be null
.off
- The offset within the provided array of the beginning of the
data to be written. It must be greater than or equal to zero
and less than or equal to the length of the provided array.len
- The number of bytes to be written. It must be greater than or
equal to zero, and the sum of off
and len
must
be less than the length of the provided array.java.io.IOException
- If an attempt was made to write beyond the end of the
array.