Package com.twelvemonkeys.io
Class FastByteArrayOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.ByteArrayOutputStream
-
- com.twelvemonkeys.io.FastByteArrayOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public final class FastByteArrayOutputStream extends java.io.ByteArrayOutputStreamAn unsynchronizedByteArrayOutputStreamimplementation. This version also has a constructor that lets you create a stream with initial content.- Version:
- $Id: FastByteArrayOutputStream.java#2 $
-
-
Constructor Summary
Constructors Constructor Description FastByteArrayOutputStream(byte[] pBuffer)Creates aByteArrayOutputStreamwith the given initial content.FastByteArrayOutputStream(int pSize)Creates aByteArrayOutputStreamwith the given initial buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.ByteArrayInputStreamcreateInputStream()Creates aByteArrayInputStreamthat reads directly from thisFastByteArrayOutputStream's byte buffer.private voidgrowIfNeeded(int pNewCount)byte[]toByteArray()voidwrite(byte[] pBytes, int pOffset, int pLength)voidwrite(int pByte)voidwriteTo(java.io.OutputStream pOut)
-
-
-
Constructor Detail
-
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 Detail
-
write
public void write(byte[] pBytes, int pOffset, int pLength)- Overrides:
writein classjava.io.ByteArrayOutputStream
-
write
public void write(int pByte)
- Overrides:
writein classjava.io.ByteArrayOutputStream
-
growIfNeeded
private void growIfNeeded(int pNewCount)
-
writeTo
public void writeTo(java.io.OutputStream pOut) throws java.io.IOException- Overrides:
writeToin classjava.io.ByteArrayOutputStream- Throws:
java.io.IOException
-
toByteArray
public byte[] toByteArray()
- Overrides:
toByteArrayin classjava.io.ByteArrayOutputStream
-
createInputStream
public java.io.ByteArrayInputStream 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.
-
-