com.sleepycat.util

Class FastOutputStream

public class FastOutputStream extends OutputStream

A replacement for ByteArrayOutputStream that does not synchronize every byte read.

This class extends OutputStream and its write() methods allow it to be used as a standard output stream. In addition, it provides writeFast() methods that are not declared to throw IOException. IOException is never thrown by this class.

Field Summary
static intDEFAULT_BUMP_SIZE
The default amount that the buffer is increased when it is full.
static intDEFAULT_INIT_SIZE
The default initial size of the buffer if no initialSize parameter is specified.
Constructor Summary
FastOutputStream()
Creates an output stream with default sizes.
FastOutputStream(int initialSize)
Creates an output stream with a default bump size and a given initial size.
FastOutputStream(int initialSize, int bumpSize)
Creates an output stream with a given bump size and initial size.
FastOutputStream(byte[] buffer)
Creates an output stream with a given initial buffer and a default bump size.
FastOutputStream(byte[] buffer, int bumpSize)
Creates an output stream with a given initial buffer and a given bump size.
Method Summary
voidaddSize(int sizeAdded)
Skip the given number of bytes in the buffer.
byte[]getBufferBytes()
Returns the buffer owned by this object.
intgetBufferLength()
Returns the length used in the internal buffer, i.e., the offset at which data will be written next.
intgetBufferOffset()
Returns the offset of the internal buffer.
voidmakeSpace(int sizeNeeded)
Ensure that at least the given number of bytes are available in the internal buffer.
voidreset()
intsize()
byte[]toByteArray()
StringtoString()
StringtoString(String encoding)
voidwrite(int b)
voidwrite(byte[] fromBuf)
voidwrite(byte[] fromBuf, int offset, int length)
voidwriteFast(int b)
Equivalent to write(int) but does not throw IOException.
voidwriteFast(byte[] fromBuf)
Equivalent to write(byte[]) but does not throw IOException.
voidwriteFast(byte[] fromBuf, int offset, int length)
Equivalent to write(byte[],int,int) but does not throw IOException.
voidwriteTo(OutputStream out)

Field Detail

DEFAULT_BUMP_SIZE

public static final int DEFAULT_BUMP_SIZE
The default amount that the buffer is increased when it is full. This constant is zero, which means to double the current buffer size.

DEFAULT_INIT_SIZE

public static final int DEFAULT_INIT_SIZE
The default initial size of the buffer if no initialSize parameter is specified. This constant is 100 bytes.

Constructor Detail

FastOutputStream

public FastOutputStream()
Creates an output stream with default sizes.

FastOutputStream

public FastOutputStream(int initialSize)
Creates an output stream with a default bump size and a given initial size.

Parameters: initialSize the initial size of the buffer.

FastOutputStream

public FastOutputStream(int initialSize, int bumpSize)
Creates an output stream with a given bump size and initial size.

Parameters: initialSize the initial size of the buffer. bumpSize the amount to increment the buffer.

FastOutputStream

public FastOutputStream(byte[] buffer)
Creates an output stream with a given initial buffer and a default bump size.

Parameters: buffer the initial buffer; will be owned by this object.

FastOutputStream

public FastOutputStream(byte[] buffer, int bumpSize)
Creates an output stream with a given initial buffer and a given bump size.

Parameters: buffer the initial buffer; will be owned by this object. bumpSize the amount to increment the buffer. If zero (the default), the current buffer size will be doubled when the buffer is full.

Method Detail

addSize

public void addSize(int sizeAdded)
Skip the given number of bytes in the buffer.

Parameters: sizeAdded number of bytes to skip.

getBufferBytes

public byte[] getBufferBytes()
Returns the buffer owned by this object.

Returns: the buffer.

getBufferLength

public int getBufferLength()
Returns the length used in the internal buffer, i.e., the offset at which data will be written next.

Returns: the buffer length.

getBufferOffset

public int getBufferOffset()
Returns the offset of the internal buffer.

Returns: always zero currently.

makeSpace

public void makeSpace(int sizeNeeded)
Ensure that at least the given number of bytes are available in the internal buffer.

Parameters: sizeNeeded the number of bytes desired.

reset

public void reset()

size

public int size()

toByteArray

public byte[] toByteArray()

toString

public String toString()

toString

public String toString(String encoding)

write

public void write(int b)

write

public void write(byte[] fromBuf)

write

public void write(byte[] fromBuf, int offset, int length)

writeFast

public final void writeFast(int b)
Equivalent to write(int) but does not throw IOException.

See Also: FastOutputStream

writeFast

public final void writeFast(byte[] fromBuf)
Equivalent to write(byte[]) but does not throw IOException.

See Also: (byte[])

writeFast

public final void writeFast(byte[] fromBuf, int offset, int length)
Equivalent to write(byte[],int,int) but does not throw IOException.

See Also: (byte[],int,int)

writeTo

public void writeTo(OutputStream out)