Class RtfByteArrayBuffer

java.lang.Object
java.io.OutputStream
com.lowagie.text.rtf.document.output.RtfByteArrayBuffer
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public final class RtfByteArrayBuffer extends OutputStream
A RtfByteArrayBuffer works much like ByteArrayOutputStream but is cheaper and faster in most cases (exception: large writes when reusing buffers).
Version:
$Id: RtfByteArrayBuffer.java 4065 2009-09-16 23:09:11Z psoares33 $
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final List<byte[]>
     
    private byte[]
     
    private int
     
    private int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new buffer with a default initial size of 128 bytes.
    RtfByteArrayBuffer(int bufferSize)
    Creates a new buffer with the given initial size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(byte[] a)
    Appends the given array to this buffer without copying (if possible).
    void
    append(byte[][] a)
    Appends all arrays to this buffer without copying (if possible).
    private void
     
    private void
    flushBuffer(int reqSize)
     
    void
    Resets this buffer.
    long
    Returns the number of bytes that have been written to this buffer so far.
    byte[]
    Allocates a new array and copies all data that has been written to this buffer to the newly allocated array.
    byte[][]
    Returns the internal list of byte array buffers without copying the buffer contents.
     
    void
    write(byte[] src)
    Copies the given array to the internal buffer.
    void
    write(byte[] src, int off, int len)
    Copies len bytes starting at position off from the array src to the internal buffer.
    void
    write(int b)
    Copies the given byte to the internal buffer.
    long
    Writes all bytes available in the given inputstream to this buffer.
    private void
    writeLoop(byte[] src, int off, int len)
     
    void
    Writes all data that has been written to this buffer to the given output stream.

    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

    • arrays

      private final List<byte[]> arrays
    • buffer

      private byte[] buffer
    • pos

      private int pos
    • size

      private int size
  • Constructor Details

    • RtfByteArrayBuffer

      public RtfByteArrayBuffer()
      Constructs a new buffer with a default initial size of 128 bytes.
    • RtfByteArrayBuffer

      public RtfByteArrayBuffer(int bufferSize)
      Creates a new buffer with the given initial size.
      Parameters:
      bufferSize - desired initial size in bytes
  • Method Details

    • toString

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

      public void reset()
      Resets this buffer.
    • size

      public long size()
      Returns the number of bytes that have been written to this buffer so far.
      Returns:
      number of bytes written to this buffer
    • flushBuffer

      private void flushBuffer()
    • flushBuffer

      private void flushBuffer(int reqSize)
    • write

      public void write(int b)
      Copies the given byte to the internal buffer.
      Specified by:
      write in class OutputStream
      Parameters:
      b -
    • write

      public void write(byte[] src)
      Copies the given array to the internal buffer.
      Overrides:
      write in class OutputStream
      Parameters:
      src -
    • write

      public void write(byte[] src, int off, int len)
      Copies len bytes starting at position off from the array src to the internal buffer.
      Overrides:
      write in class OutputStream
      Parameters:
      src -
      off -
      len -
    • writeLoop

      private void writeLoop(byte[] src, int off, int len)
    • write

      public long write(InputStream in) throws IOException
      Writes all bytes available in the given inputstream to this buffer.
      Parameters:
      in -
      Returns:
      number of bytes written
      Throws:
      IOException
    • append

      public void append(byte[] a)
      Appends the given array to this buffer without copying (if possible).
      Parameters:
      a -
    • append

      public void append(byte[][] a)
      Appends all arrays to this buffer without copying (if possible).
      Parameters:
      a -
    • toByteArrayArray

      public byte[][] toByteArrayArray()
      Returns the internal list of byte array buffers without copying the buffer contents.
      Returns:
      number of bytes written
    • toByteArray

      public byte[] toByteArray()
      Allocates a new array and copies all data that has been written to this buffer to the newly allocated array.
      Returns:
      a new byte array
    • writeTo

      public void writeTo(OutputStream out) throws IOException
      Writes all data that has been written to this buffer to the given output stream.
      Parameters:
      out -
      Throws:
      IOException