Class FastByteArrayOutputStream
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
com.twelvemonkeys.io.FastByteArrayOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
An unsynchronized
ByteArrayOutputStream implementation. This version
also has a constructor that lets you create a stream with initial content.- Version:
- $Id: FastByteArrayOutputStream.java#2 $
-
Field Summary
Fields inherited from class ByteArrayOutputStream
buf, count -
Constructor Summary
ConstructorsConstructorDescriptionFastByteArrayOutputStream(byte[] pBuffer) Creates aByteArrayOutputStreamwith the given initial content.FastByteArrayOutputStream(int pSize) Creates aByteArrayOutputStreamwith the given initial buffer size. -
Method Summary
Modifier and TypeMethodDescriptionCreates aByteArrayInputStreamthat reads directly from thisFastByteArrayOutputStream's byte buffer.private voidgrowIfNeeded(int pNewCount) byte[]voidwrite(byte[] pBytes, int pOffset, int pLength) voidwrite(int pByte) voidwriteTo(OutputStream pOut) Methods inherited from class ByteArrayOutputStream
close, reset, size, toString, toString, toString, toString, writeBytesMethods inherited from class OutputStream
flush, nullOutputStream, write
-
Constructor Details
-
FastByteArrayOutputStream
public FastByteArrayOutputStream(int pSize) Creates aByteArrayOutputStreamwith the given initial buffer size.- Parameters:
pSize- initial buffer size
-
FastByteArrayOutputStream
public FastByteArrayOutputStream(byte[] pBuffer) Creates aByteArrayOutputStreamwith the given initial content.Note that the buffer is not cloned, for maximum performance.
- Parameters:
pBuffer- initial buffer
-
-
Method Details
-
write
public void write(byte[] pBytes, int pOffset, int pLength) - Overrides:
writein classByteArrayOutputStream
-
write
public void write(int pByte) - Overrides:
writein classByteArrayOutputStream
-
growIfNeeded
private void growIfNeeded(int pNewCount) -
writeTo
- Overrides:
writeToin classByteArrayOutputStream- Throws:
IOException
-
toByteArray
public byte[] toByteArray()- Overrides:
toByteArrayin classByteArrayOutputStream
-
createInputStream
Creates aByteArrayInputStreamthat reads directly from thisFastByteArrayOutputStream'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.
-