|
JIU 0.14.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
net.sourceforge.jiu.util.SeekableByteArrayOutputStream
public class SeekableByteArrayOutputStream
An extension of OutputStream
that writes data to an internal
byte array, resizing it when necessary.
Similar to ByteArrayOutputStream
, but also enables seeking and truncating.
Constructor Summary | |
---|---|
SeekableByteArrayOutputStream()
Creates a new object of this class, setting initial capacity and increment size to default values. |
|
SeekableByteArrayOutputStream(int initialCapacity)
Creates a new object of this class, setting initial capacity to the argument value. |
|
SeekableByteArrayOutputStream(int initialCapacity,
int increment)
Creates a new object of this class, setting initial capacity and increment to the argument values. |
Method Summary | |
---|---|
void |
close()
Closes this output stream. |
int |
getPosition()
Returns the current offset in the output stream. |
int |
getSize()
Returns the current size of the output stream. |
void |
seek(int newOffset)
Sets the current position in the output stream to the argument. |
byte[] |
toByteArray()
Allocates a new byte[] object, copies getSize() bytes
from the internal byte array to that new array and returns the array. |
void |
truncate()
Removes all bytes after the current position. |
void |
write(byte[] data)
Write the complete argument array to this stream. |
void |
write(byte[] src,
int srcOffset,
int num)
Write some bytes from the argument array to this stream. |
void |
write(int b)
Writes the least significant eight bits of the argument int to the internal array. |
void |
writeTo(OutputStream out)
Writes the bytes in the internal byte array to the argument output stream. |
Methods inherited from class java.io.OutputStream |
---|
flush |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SeekableByteArrayOutputStream()
public SeekableByteArrayOutputStream(int initialCapacity)
initialCapacity
- the number of bytes that are allocated in this constructor (0 or larger)public SeekableByteArrayOutputStream(int initialCapacity, int increment)
initialCapacity
- the number of bytes that are allocated in this constructor (0 or larger)increment
- the number of bytes by which the internal byte array is increased if it is full (1 or larger)Method Detail |
---|
public void close() throws IOException
close
in interface Closeable
close
in class OutputStream
IOException
public int getPosition()
getSize()
.
public int getSize()
public void seek(int newOffset) throws IOException
newOffset
- new offset into the file, must be >= 0 and <= getSize()
IOException
- if the argument is invalidpublic byte[] toByteArray()
byte[]
object, copies getSize()
bytes
from the internal byte array to that new array and returns the array.
public void truncate()
getSize()
is equal to getPosition()
.
public void write(int b) throws IOException
int
to the internal array.
write
in class OutputStream
b
- int variable that stores the byte value to be written
IOException
public void write(byte[] data) throws IOException
write(data, 0, data.length);
.
write
in class OutputStream
data
- array to be copied to this stream
IOException
public void write(byte[] src, int srcOffset, int num) throws IOException
write
in class OutputStream
src
- the array from which data is copiedsrcOffset
- int index into that array pointing to the first byte to be copiednum
- number of bytes to be copied
IOException
public void writeTo(OutputStream out) throws IOException
byte[] copy = toByteArray(); out.write(copy, 0, copy.length);However, you with this method you save the allocation of an additional byte array and the copying to that new array.
out
- the output stream to which this stream's content is copied
IOException
- if out has a problem writing the bytes
|
JIU 0.14.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |