|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> services >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.iapi.services.io
Class DynamicByteArrayOutputStream

java.lang.Objectjava.io.OutputStream
org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream
- public class DynamicByteArrayOutputStream
- extends java.io.OutputStream
A DynamicByteArrayOutputStream allows writing to a dynamically resizable array of bytes. In addition to dynamic resizing, this extension allows the user of this class to have more control over the position of the stream and can get a direct reference of the array.
| Field Summary | |
private int |
beginPosition
|
private byte[] |
buf
|
private static int |
INITIAL_SIZE
|
private int |
position
|
private int |
used
|
| Constructor Summary | |
DynamicByteArrayOutputStream()
|
|
DynamicByteArrayOutputStream(byte[] data)
|
|
DynamicByteArrayOutputStream(DynamicByteArrayOutputStream toBeCloned)
|
|
DynamicByteArrayOutputStream(int size)
|
|
| Method Summary | |
void |
close()
This method closes the stream. |
void |
discardLeft(int amountToShrinkBy)
Shrink the buffer left by the amount given. |
private void |
expandBuffer(int minExtension)
Expand the buffer by at least the number of bytes requested in minExtension. |
int |
getBeginPosition()
Get the current position in the stream |
byte[] |
getByteArray()
Get a reference to the byte array stored in the byte array output stream. |
int |
getPosition()
Get the current position in the stream |
int |
getUsed()
Get the number of bytes that was used. |
void |
reset()
Reset the stream for reuse |
void |
setBeginPosition(int newBeginPosition)
Set the begin position of the stream pointer. |
void |
setPosition(int newPosition)
Set the position of the stream pointer. |
void |
write(byte[] b,
int off,
int len)
This method writes len bytes from the specified array
b starting at index off into the array. |
void |
write(int b)
This method writes a single byte to the output stream. |
(package private) void |
writeCompleteStream(java.io.InputStream dataIn,
int len)
|
| Methods inherited from class java.io.OutputStream |
flush, write |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
INITIAL_SIZE
private static int INITIAL_SIZE
buf
private byte[] buf
position
private int position
used
private int used
beginPosition
private int beginPosition
| Constructor Detail |
DynamicByteArrayOutputStream
public DynamicByteArrayOutputStream()
DynamicByteArrayOutputStream
public DynamicByteArrayOutputStream(int size)
DynamicByteArrayOutputStream
public DynamicByteArrayOutputStream(byte[] data)
DynamicByteArrayOutputStream
public DynamicByteArrayOutputStream(DynamicByteArrayOutputStream toBeCloned)
| Method Detail |
write
public void write(int b)
- Description copied from class:
java.io.OutputStream - This method writes a single byte to the output stream. The byte written
is the low eight bits of the
intpassed and a argument.Subclasses must provide an implementation of this abstract method
write
public void write(byte[] b,
int off,
int len)
- Description copied from class:
java.io.OutputStream - This method writes
lenbytes from the specified arraybstarting at indexoffinto the array.This method in this class calls the single byte
write()method in a loop until all bytes have been written. Subclasses should override this method if possible in order to provide a more efficent implementation.
writeCompleteStream
void writeCompleteStream(java.io.InputStream dataIn, int len) throws java.io.IOException
close
public void close()
- Description copied from class:
java.io.OutputStream - This method closes the stream. Any internal or native resources
associated with this stream are freed. Any subsequent attempt to
access the stream might throw an exception.
This method in this class does nothing.
reset
public void reset()
- Reset the stream for reuse
getByteArray
public byte[] getByteArray()
- Get a reference to the byte array stored in the byte array output
stream. Note that the byte array may be longer that getPosition().
Bytes beyond and including the current poistion are invalid.
getUsed
public int getUsed()
- Get the number of bytes that was used.
getPosition
public int getPosition()
- Get the current position in the stream
getBeginPosition
public int getBeginPosition()
- Get the current position in the stream
setPosition
public void setPosition(int newPosition)
- Set the position of the stream pointer.
It is up to the caller to make sure the stream has no gap of garbage in
it or useful information is not left out at the end because the stream
does not remember anything about the previous position.
setBeginPosition
public void setBeginPosition(int newBeginPosition)
- Set the begin position of the stream pointer.
If the newBeginPosition is larger than the stream itself,
then, the begin position is not set.
discardLeft
public void discardLeft(int amountToShrinkBy)
- Shrink the buffer left by the amount given. Ie.
bytes from 0 to amountToShrinkBy are thrown away
expandBuffer
private void expandBuffer(int minExtension)
- Expand the buffer by at least the number of bytes requested in minExtension.
To optimize performance and reduce memory copies and allocation, we have a staged buffer
expansion.
- buf.length < 128k - increase by 4k
- buf.length < 1Mb - increase by 128k
- otherwise increase by 1Mb.
|
|||||||||
| Home >> All >> org >> apache >> derby >> iapi >> services >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC