com.twelvemonkeys.io
Class FastByteArrayOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ByteArrayOutputStream
          extended by com.twelvemonkeys.io.FastByteArrayOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public final class FastByteArrayOutputStream
extends java.io.ByteArrayOutputStream

An unsynchronized ByteArrayOutputStream implementation. This version also has a constructor that lets you create a stream with initial content.

Version:
$Id: FastByteArrayOutputStream.java#2 $
Author:
Harald Kuhr

Field Summary
protected  int maxGrowSize
          Max grow size (unless if writing more than this amount of bytes)
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
FastByteArrayOutputStream(byte[] pBuffer)
          Creates a ByteArrayOutputStream with the given initial content.
FastByteArrayOutputStream(int pSize)
          Creates a ByteArrayOutputStream with the given initial buffer size.
 
Method Summary
 java.io.ByteArrayInputStream createInputStream()
          Creates a ByteArrayInputStream that reads directly from this FastByteArrayOutputStream's byte buffer.
 byte[] toByteArray()
           
 void write(byte[] pBytes, int pOffset, int pLength)
           
 void write(int pByte)
           
 void writeTo(java.io.OutputStream pOut)
           
 
Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toString, toString, toString
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

maxGrowSize

protected int maxGrowSize
Max grow size (unless if writing more than this amount of bytes)

Constructor Detail

FastByteArrayOutputStream

public FastByteArrayOutputStream(int pSize)
Creates a ByteArrayOutputStream with the given initial buffer size.

Parameters:
pSize - initial buffer size

FastByteArrayOutputStream

public FastByteArrayOutputStream(byte[] pBuffer)
Creates a ByteArrayOutputStream with the given initial content.

Note that the buffer is not cloned, for maximum performance.

Parameters:
pBuffer - initial buffer
Method Detail

write

public void write(byte[] pBytes,
                  int pOffset,
                  int pLength)
Overrides:
write in class java.io.ByteArrayOutputStream

write

public void write(int pByte)
Overrides:
write in class java.io.ByteArrayOutputStream

writeTo

public void writeTo(java.io.OutputStream pOut)
             throws java.io.IOException
Overrides:
writeTo in class java.io.ByteArrayOutputStream
Throws:
java.io.IOException

toByteArray

public byte[] toByteArray()
Overrides:
toByteArray in class java.io.ByteArrayOutputStream

createInputStream

public java.io.ByteArrayInputStream createInputStream()
Creates a ByteArrayInputStream that reads directly from this FastByteArrayOutputStream's byte buffer. The buffer is not cloned, for maximum performance.

Note that care needs to be taken to avoid writes to this output stream after the input stream is created. Failing to do so, may result in unpredictable behaviour.

Returns:
a new ByteArrayInputStream, reading from this stream's buffer.


Copyright © 2014. All Rights Reserved.