Package com.sleepycat.util
Class FastOutputStream
java.lang.Object
java.io.OutputStream
com.sleepycat.util.FastOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
- Direct Known Subclasses:
TupleOutput
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
FieldsModifier and TypeFieldDescriptionstatic final intThe default amount that the buffer is increased when it is full.static final intThe default initial size of the buffer if no initialSize parameter is specified. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an output stream with default sizes.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.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. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSize(int sizeAdded) Skip the given number of bytes in the buffer.byte[]Returns the buffer owned by this object.intReturns the length used in the internal buffer, i.e., the offset at which data will be written next.intReturns 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[]toString()voidwrite(byte[] fromBuf) voidwrite(byte[] fromBuf, int offset, int length) voidwrite(int b) final voidwriteFast(byte[] fromBuf) Equivalent towrite(byte[])but does not throwIOException.final voidwriteFast(byte[] fromBuf, int offset, int length) Equivalent towrite(byte[],int,int)but does not throwIOException.final voidwriteFast(int b) Equivalent towrite(int)but does not throwIOException.voidwriteTo(OutputStream out) Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream
-
Field Details
-
DEFAULT_INIT_SIZE
public static final int DEFAULT_INIT_SIZEThe default initial size of the buffer if no initialSize parameter is specified. This constant is 100 bytes.- See Also:
-
DEFAULT_BUMP_SIZE
public static final int DEFAULT_BUMP_SIZEThe default amount that the buffer is increased when it is full. This constant is zero, which means to double the current buffer size.- See Also:
-
-
Constructor Details
-
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 Details
-
size
public int size() -
reset
public void reset() -
write
public void write(int b) - Specified by:
writein classOutputStream
-
write
public void write(byte[] fromBuf) - Overrides:
writein classOutputStream
-
write
public void write(byte[] fromBuf, int offset, int length) - Overrides:
writein classOutputStream
-
writeTo
- Throws:
IOException
-
toString
-
toString
- Throws:
UnsupportedEncodingException
-
toByteArray
public byte[] toByteArray() -
writeFast
public final void writeFast(int b) Equivalent towrite(int)but does not throwIOException.- See Also:
-
writeFast
public final void writeFast(byte[] fromBuf) Equivalent towrite(byte[])but does not throwIOException.- See Also:
-
writeFast
public final void writeFast(byte[] fromBuf, int offset, int length) Equivalent towrite(byte[],int,int)but does not throwIOException.- See Also:
-
getBufferBytes
public byte[] getBufferBytes()Returns the buffer owned by this object.- Returns:
- the buffer.
-
getBufferOffset
public int getBufferOffset()Returns the offset of the internal buffer.- Returns:
- always zero currently.
-
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.
-
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.
-
addSize
public void addSize(int sizeAdded) Skip the given number of bytes in the buffer.- Parameters:
sizeAdded- number of bytes to skip.
-