org.mortbay.util

Class ByteBufferOutputStream

public class ByteBufferOutputStream extends OutputStream

ByteBuffer OutputStream. This stream is similar to the java.io.ByteArrayOutputStream, except that it maintains a reserve of bytes at the start of the buffer and allows efficient prepending of data.

Version: $Revision: 1.18 $

Author: Greg Wilkins (gregw)

Field Summary
protected byte[]_buf
Constructor Summary
ByteBufferOutputStream()
Constructor.
ByteBufferOutputStream(int capacity)
Constructor.
ByteBufferOutputStream(int capacity, int preReserve)
Constructor.
ByteBufferOutputStream(int bufferSize, int preReserve, int postReserve)
Constructor.
Method Summary
intbufferSize()
intcapacity()
voidclose()
voiddestroy()
voidensureCapacity(int n)
voidensureReserve(int n)
voidensureSize(int bufSize)
voidensureSize(int bufSize, int pre, int post)
voidensureSpareCapacity(int n)
voidflush()
booleanisFixed()
intpostReserve()
voidpostwrite(byte b)
Write bytes into the postreserve.
voidpostwrite(byte[] b, int offset, int length)
Write bytes into the postreserve.
intpreReserve()
voidprewrite(int b)
Write byte to start of the buffer.
voidprewrite(byte[] b)
Write byte array to start of the buffer.
voidprewrite(byte[] b, int offset, int length)
Write byte range to start of the buffer.
voidreset(int reserve)
voidresetStream()
voidsetFixed(boolean fixed)
intsize()
intspareCapacity()
voidwrite(int b)
voidwrite(byte[] b)
voidwrite(byte[] b, int offset, int length)
voidwriteTo(OutputStream out)

Field Detail

_buf

protected byte[] _buf

Constructor Detail

ByteBufferOutputStream

public ByteBufferOutputStream()
Constructor.

ByteBufferOutputStream

public ByteBufferOutputStream(int capacity)
Constructor.

Parameters: capacity Buffer capacity

ByteBufferOutputStream

public ByteBufferOutputStream(int capacity, int preReserve)
Constructor.

Parameters: capacity Buffer capacity. preReserve The reserve of byte for prepending

ByteBufferOutputStream

public ByteBufferOutputStream(int bufferSize, int preReserve, int postReserve)
Constructor.

Parameters: bufferSize The size of the buffer == capacity+preReserve+postReserve preReserve The reserve of byte for prepending postReserve The reserve of byte for appending

Method Detail

bufferSize

public int bufferSize()

Returns: The size of the buffer.

capacity

public int capacity()

Returns: The capacity of the buffer excluding pre and post reserves.

close

public void close()

destroy

public void destroy()

ensureCapacity

public void ensureCapacity(int n)

ensureReserve

public void ensureReserve(int n)

ensureSize

public void ensureSize(int bufSize)

ensureSize

public void ensureSize(int bufSize, int pre, int post)

ensureSpareCapacity

public void ensureSpareCapacity(int n)

flush

public void flush()

isFixed

public boolean isFixed()

Returns: True if the buffer cannot be expanded

postReserve

public int postReserve()

Returns: The current post reserve.

postwrite

public void postwrite(byte b)
Write bytes into the postreserve. The capacity is not checked.

Parameters: b offset length

Throws: IOException

postwrite

public void postwrite(byte[] b, int offset, int length)
Write bytes into the postreserve. The capacity is not checked.

Parameters: b offset length

Throws: IOException

preReserve

public int preReserve()

Returns: The current pre reserve.

prewrite

public void prewrite(int b)
Write byte to start of the buffer.

Parameters: b

prewrite

public void prewrite(byte[] b)
Write byte array to start of the buffer.

Parameters: b

prewrite

public void prewrite(byte[] b, int offset, int length)
Write byte range to start of the buffer.

Parameters: b offset length

reset

public void reset(int reserve)

resetStream

public void resetStream()

setFixed

public void setFixed(boolean fixed)

Parameters: fixed True if the buffer cannot be expanded

size

public int size()

Returns: The size of valid data in the buffer.

spareCapacity

public int spareCapacity()

Returns: The available capacity of the buffer excluding pre and post reserves and data already written.

write

public void write(int b)

write

public void write(byte[] b)

write

public void write(byte[] b, int offset, int length)

writeTo

public void writeTo(OutputStream out)
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.