com.lowagie.text.rtf.document.output

Class RtfByteArrayBuffer

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 2785 2007-05-24 15:45:47Z hallm $

Author: Thomas Bickel (tmb99@inode.at)

Field Summary
Listarrays
byte[]buffer
intpos
intsize
Constructor Summary
RtfByteArrayBuffer()
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
voidappend(byte[] a)
Appends the given array to this buffer without copying (if possible).
voidappend(byte[][] a)
Appends all arrays to this buffer without copying (if possible).
voidflushBuffer()
voidflushBuffer(int reqSize)
voidreset()
Resets this buffer.
longsize()
Returns the number of bytes that have been written to this buffer so far.
byte[]toByteArray()
Allocates a new array and copies all data that has been written to this buffer to the newly allocated array.
byte[][]toByteArrayArray()
Returns the internal list of byte array buffers without copying the buffer contents.
StringtoString()
voidwrite(int b)
Copies the given byte to the internal buffer.
voidwrite(byte[] src)
Copies the given array to the internal buffer.
voidwrite(byte[] src, int off, int len)
Copies len bytes starting at position off from the array src to the internal buffer.
longwrite(InputStream in)
Writes all bytes available in the given inputstream to this buffer.
voidwriteLoop(byte[] src, int off, int len)
voidwriteTo(OutputStream out)
Writes all data that has been written to this buffer to the given output stream.

Field Detail

arrays

private final List arrays

buffer

private byte[] buffer

pos

private int pos

size

private int size

Constructor Detail

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 Detail

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

flushBuffer

private void flushBuffer()

flushBuffer

private void flushBuffer(int reqSize)

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

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

toByteArrayArray

public byte[][] toByteArrayArray()
Returns the internal list of byte array buffers without copying the buffer contents.

Returns: number of bytes written

toString

public String toString()

write

public void write(int b)
Copies the given byte to the internal buffer.

Parameters: b

write

public void write(byte[] src)
Copies the given array to the internal buffer.

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.

Parameters: src off len

write

public long write(InputStream in)
Writes all bytes available in the given inputstream to this buffer.

Parameters: in

Returns: number of bytes written

Throws: IOException

writeLoop

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

writeTo

public void writeTo(OutputStream out)
Writes all data that has been written to this buffer to the given output stream.

Parameters: out

Throws: IOException