org.mortbay.util
Class ByteBufferOutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--org.mortbay.util.ByteBufferOutputStream
Direct Known Subclasses:
BufferedOutputStream

public class ByteBufferOutputStream
extends java.io.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.12 $
Author:
Greg Wilkins (gregw)

Constructor Summary
ByteBufferOutputStream()
          Constructor.
ByteBufferOutputStream(int capacity)
          Constructor.
ByteBufferOutputStream(int capacity, int preReserve)
          Constructor.
ByteBufferOutputStream(int bufferSize, int preReserve, int postReserve)
          Constructor.
 
Method Summary
 int bufferSize()
           
 int capacity()
           
 void close()
           
 void destroy()
           
 void ensureCapacity(int n)
           
 void ensureReserve(int n)
           
 void ensureSize(int bufSize)
           
 void ensureSize(int bufSize, int pre, int post)
           
 void ensureSpareCapacity(int n)
           
 void flush()
           
 boolean isFixed()
           
 int postReserve()
           
 void postwrite(byte[] b, int offset, int length)
          Write bytes into the postreserve.
 int preReserve()
           
 void prewrite(byte[] b)
          Write byte array to start of the buffer.
 void prewrite(byte[] b, int offset, int length)
          Write byte range to start of the buffer.
 void prewrite(int b)
          Write byte to start of the buffer.
 void reset(int reserve)
           
 void resetStream()
           
 void setFixed(boolean fixed)
           
 int size()
           
 int spareCapacity()
           
 void write(byte[] b)
           
 void write(byte[] b, int offset, int length)
           
 void write(int b)
           
 void writeTo(java.io.OutputStream out)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

isFixed

public boolean isFixed()
Returns:
True if the buffer cannot be expanded

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.

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.

spareCapacity

public int spareCapacity()
Returns:
The available capacity of the buffer excluding pre and post reserves and data already written.

preReserve

public int preReserve()
Returns:
The current pre reserve.

postReserve

public int postReserve()
Returns:
The current post reserve.

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
java.io.IOException

write

public void write(byte[] b,
                  int offset,
                  int length)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
java.io.IOException

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 -

postwrite

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

Parameters:
b -
offset -
length -
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Overrides:
flush in class java.io.OutputStream
java.io.IOException

resetStream

public void resetStream()

reset

public void reset(int reserve)

close

public void close()
           throws java.io.IOException
Overrides:
close in class java.io.OutputStream
java.io.IOException

destroy

public void destroy()

ensureReserve

public void ensureReserve(int n)

ensureSize

public void ensureSize(int bufSize)
                throws java.io.IOException
java.io.IOException

ensureSize

public void ensureSize(int bufSize,
                       int pre,
                       int post)
                throws java.io.IOException
java.io.IOException

ensureSpareCapacity

public void ensureSpareCapacity(int n)
                         throws java.io.IOException
java.io.IOException

ensureCapacity

public void ensureCapacity(int n)
                    throws java.io.IOException
java.io.IOException


Copyright ? 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.