org.icepdf.core.io
Class ConservativeSizingByteArrayOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.icepdf.core.io.ConservativeSizingByteArrayOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class ConservativeSizingByteArrayOutputStream
extends java.io.OutputStream

Since:
2.0
Author:
Mark Collette

Field Summary
protected  byte[] buf
           
protected  int count
           
 
Constructor Summary
ConservativeSizingByteArrayOutputStream(byte[] buffer)
          Creates a new byte array output stream, with the given initial buffer
ConservativeSizingByteArrayOutputStream(int capacity)
          Creates a new byte array output stream, with the given initial buffer capacity
 
Method Summary
protected  byte[] allocateByteArray(int size)
           
 byte[] relinquishByteArray()
          Allows the caller to take ownership of this output stream's byte array.
 void reset()
           
protected  void resizeArrayToFit(int newCount)
           
 int size()
          Returns the current size of the buffer.
 byte[] toByteArray()
          Creates a newly allocated byte array.
 boolean trim()
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

protected byte[] buf

count

protected int count
Constructor Detail

ConservativeSizingByteArrayOutputStream

public ConservativeSizingByteArrayOutputStream(int capacity)
Creates a new byte array output stream, with the given initial buffer capacity

Parameters:
capacity - The initial capacity
Throws:
java.lang.IllegalArgumentException - if capacity is negative

ConservativeSizingByteArrayOutputStream

public ConservativeSizingByteArrayOutputStream(byte[] buffer)
Creates a new byte array output stream, with the given initial buffer

Parameters:
buffer - The initial buffer
Throws:
java.lang.IllegalArgumentException - if capacity is negative
Method Detail

write

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

write

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

reset

public void reset()

toByteArray

public byte[] toByteArray()
Creates a newly allocated byte array. Its length is equal to the current count of bytes in this output stream. The data bytes are then copied into it.

Returns:
The current contents of this output stream, as a byte array.

size

public int size()
Returns the current size of the buffer.

Returns:
The number of valid bytes in this output stream.

relinquishByteArray

public byte[] relinquishByteArray()
Allows the caller to take ownership of this output stream's byte array. Note that this output stream will then make a new small buffer for itself and reset its size information, meaning that you should call size() before this.


trim

public boolean trim()
Returns:
true, if there was enough memory to trim buf; false otherwise

resizeArrayToFit

protected void resizeArrayToFit(int newCount)

allocateByteArray

protected byte[] allocateByteArray(int size)