Package com.unboundid.util
Class FixedArrayOutputStream
java.lang.Object
java.io.OutputStream
com.unboundid.util.FixedArrayOutputStream
- All Implemented Interfaces:
Closeable,Flushable,Serializable,AutoCloseable
@Mutable
@ThreadSafety(level=NOT_THREADSAFE)
public final class FixedArrayOutputStream
extends OutputStream
implements Serializable
This class provides an
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.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionFixedArrayOutputStream(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. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this output stream.voidflush()Flushes this output stream.byte[]Retrieves the backing array used by this output stream.intRetrieves the number of bytes that have been written so far to this output stream.intRetrieves the initial position provided when this output stream was created.intRetrieves the maximum number of bytes that may be written to this output stream.voidwrite(byte[] b) Writes the contents of the provided array to this output stream.voidwrite(byte[] b, int off, int len) Writes the contents of the provided array to this output stream.voidwrite(int b) Writes the provided byte to this output stream.Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
FixedArrayOutputStream
Creates a new output stream that will write data to the provided array. It will use the entire array.- Parameters:
array- The array to which data will be written. It must not benull.
-
FixedArrayOutputStream
Creates a new output stream that will write data to the provided array. It will use the specified portion of the array.- Parameters:
array- The array to which data will be written. It must not benull.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 providedposvalue.
-
-
Method Details
-
getBackingArray
Retrieves the backing array used by this output stream.- Returns:
- The backing array used by this output stream.
-
getInitialPosition
Retrieves the initial position provided when this output stream was created.- Returns:
- The initial position provided when this output stream was created.
-
getLength
Retrieves the maximum number of bytes that may be written to this output stream.- Returns:
- The maximum number of bytes that may be written to this output stream.
-
getBytesWritten
Retrieves the number of bytes that have been written so far to this output stream.- Returns:
- The number of bytes that have been written so far to this output stream.
-
close
Closes this output stream. This has no effect.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream
-
flush
Flushes this output stream. This has no effect.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream
-
write
Writes the provided byte to this output stream.- Specified by:
writein classOutputStream- Parameters:
b- The byte to be written.- Throws:
IOException- If an attempt was made to write beyond the end of the array.
-
write
Writes the contents of the provided array to this output stream.- Overrides:
writein classOutputStream- Parameters:
b- The byte array containing the data to be written. It must not benull.- Throws:
IOException- If an attempt was made to write beyond the end of the array.
-
write
Writes the contents of the provided array to this output stream.- Overrides:
writein classOutputStream- Parameters:
b- The byte array containing the data to be written. It must not benull.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 ofoffandlenmust be less than the length of the provided array.- Throws:
IOException- If an attempt was made to write beyond the end of the array.
-