org.icepdf.core.io
Class ConservativeSizingByteArrayOutputStream
java.lang.Object
java.io.OutputStream
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
| 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 |
memoryManager
protected MemoryManager memoryManager
buf
protected byte[] buf
count
protected int count
ConservativeSizingByteArrayOutputStream
public ConservativeSizingByteArrayOutputStream(int capacity,
MemoryManager mm)
- 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,
MemoryManager mm)
- 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
setMemoryManager
public void setMemoryManager(MemoryManager mm)
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,
boolean returnNullIfNoMemory)