Class FastOutputStream

java.lang.Object
java.io.OutputStream
com.sleepycat.util.FastOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
Direct Known Subclasses:
TupleOutput

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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default amount that the buffer is increased when it is full.
    static final int
    The default initial size of the buffer if no initialSize parameter is specified.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates 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 Type
    Method
    Description
    void
    addSize(int sizeAdded)
    Skip the given number of bytes in the buffer.
    byte[]
    Returns the buffer owned by this object.
    int
    Returns the length used in the internal buffer, i.e., the offset at which data will be written next.
    int
    Returns the offset of the internal buffer.
    void
    makeSpace(int sizeNeeded)
    Ensure that at least the given number of bytes are available in the internal buffer.
    void
     
    int
     
    byte[]
     
     
    toString(String encoding)
     
    void
    write(byte[] fromBuf)
     
    void
    write(byte[] fromBuf, int offset, int length)
     
    void
    write(int b)
     
    final void
    writeFast(byte[] fromBuf)
    Equivalent to write(byte[]) but does not throw IOException.
    final void
    writeFast(byte[] fromBuf, int offset, int length)
    Equivalent to write(byte[],int,int) but does not throw IOException.
    final void
    writeFast(int b)
    Equivalent to write(int) but does not throw IOException.
    void
     

    Methods inherited from class java.io.OutputStream

    close, flush, nullOutputStream

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • 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.
      See Also:
    • 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.
      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:
      write in class OutputStream
    • write

      public void write(byte[] fromBuf)
      Overrides:
      write in class OutputStream
    • write

      public void write(byte[] fromBuf, int offset, int length)
      Overrides:
      write in class OutputStream
    • writeTo

      public void writeTo(OutputStream out) throws IOException
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(String encoding) throws UnsupportedEncodingException
      Throws:
      UnsupportedEncodingException
    • toByteArray

      public byte[] toByteArray()
    • writeFast

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

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

      public final void writeFast(byte[] fromBuf, int offset, int length)
      Equivalent to write(byte[],int,int) but does not throw IOException.
      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.