Class FastByteArrayOutputStream

java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
com.twelvemonkeys.io.FastByteArrayOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public final class FastByteArrayOutputStream extends ByteArrayOutputStream
An unsynchronized ByteArrayOutputStream implementation. This version also has a constructor that lets you create a stream with initial content.
Version:
$Id: FastByteArrayOutputStream.java#2 $
Author:
Harald Kuhr
  • Constructor Details

    • FastByteArrayOutputStream

      public FastByteArrayOutputStream(int pSize)
      Creates a ByteArrayOutputStream with the given initial buffer size.
      Parameters:
      pSize - initial buffer size
    • FastByteArrayOutputStream

      public FastByteArrayOutputStream(byte[] pBuffer)
      Creates a ByteArrayOutputStream with the given initial content.

      Note that the buffer is not cloned, for maximum performance.

      Parameters:
      pBuffer - initial buffer
  • Method Details

    • write

      public void write(byte[] pBytes, int pOffset, int pLength)
      Overrides:
      write in class ByteArrayOutputStream
    • write

      public void write(int pByte)
      Overrides:
      write in class ByteArrayOutputStream
    • writeTo

      public void writeTo(OutputStream pOut) throws IOException
      Overrides:
      writeTo in class ByteArrayOutputStream
      Throws:
      IOException
    • toByteArray

      public byte[] toByteArray()
      Overrides:
      toByteArray in class ByteArrayOutputStream
    • createInputStream

      public ByteArrayInputStream createInputStream()
      Creates a ByteArrayInputStream that reads directly from this FastByteArrayOutputStream's byte buffer. The buffer is not cloned, for maximum performance.

      Note that care needs to be taken to avoid writes to this output stream after the input stream is created. Failing to do so, may result in unpredictable behaviour.

      Returns:
      a new ByteArrayInputStream, reading from this stream's buffer.