java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
org.monte.media.io.SeekableByteArrayOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
SeekableByteArrayOutputStream.- Author:
- Werner Randelshofer
-
Field Summary
Fields inherited from class java.io.ByteArrayOutputStream
buf, count -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new byte array output stream.SeekableByteArrayOutputStream(byte[] buf) Creates a new byte array output stream, which reuses the supplied buffer.SeekableByteArrayOutputStream(int size) Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Returns the underlying byte buffer.longReturns the current byte position of the stream.voidreset()Resets thecountfield of this byte array output stream to zero, so that all currently accumulated output in the output stream is discarded.voidseek(long pos) Sets the current stream position to the desired location.voidWrites the contents of the byte array into the specified output stream.voidwrite(byte[] b, int off, int len) Writeslenbytes from the specified byte array starting at offsetoffto this byte array output stream.voidwrite(int b) Writes the specified byte to this byte array output stream.Methods inherited from class java.io.ByteArrayOutputStream
close, size, toByteArray, toString, toString, toString, toString, writeBytes, writeToMethods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Constructor Details
-
SeekableByteArrayOutputStream
public SeekableByteArrayOutputStream()Creates a new byte array output stream. The buffer capacity is initially 32 bytes, though its size increases if necessary. -
SeekableByteArrayOutputStream
public SeekableByteArrayOutputStream(int size) Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.- Parameters:
size- the initial size.- Throws:
IllegalArgumentException- if size is negative.
-
SeekableByteArrayOutputStream
public SeekableByteArrayOutputStream(byte[] buf) Creates a new byte array output stream, which reuses the supplied buffer.
-
-
Method Details
-
write
public void write(int b) Writes the specified byte to this byte array output stream.- Overrides:
writein classByteArrayOutputStream- Parameters:
b- the byte to be written.
-
write
public void write(byte[] b, int off, int len) Writeslenbytes from the specified byte array starting at offsetoffto this byte array output stream.- Overrides:
writein classByteArrayOutputStream- Parameters:
b- the data.off- the start offset in the data.len- the number of bytes to write.
-
reset
public void reset()Resets thecountfield 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.- Overrides:
resetin classByteArrayOutputStream- See Also:
-
seek
Sets the current stream position to the desired location. The next read will occur at this location. The bit offset is set to 0.An
IndexOutOfBoundsExceptionwill be thrown ifposis smaller than the flushed position (as returned bygetflushedPosition).It is legal to seek past the end of the file; an
EOFExceptionwill be thrown only if a read is performed.- Parameters:
pos- alongcontaining the desired file pointer position.- Throws:
IndexOutOfBoundsException- ifposis smaller than the flushed position.IOException- if any other I/O error occurs.
-
getStreamPosition
Returns the current byte position of the stream. The next write will take place starting at this offset.- Returns:
- a long containing the position of the stream.
- Throws:
IOException- if an I/O error occurs.
-
toOutputStream
Writes the contents of the byte array into the specified output stream.- Parameters:
out-- Throws:
IOException
-
getBuffer
public byte[] getBuffer()Returns the underlying byte buffer.
-