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.ByteArrayOutputStream
An unsynchronizedByteArrayOutputStream
implementation. This version also has a constructor that lets you create a stream with initial content.- Version:
- $Id: FastByteArrayOutputStream.java#2 $
- Author:
- Harald Kuhr
-
-
Constructor Summary
Constructors Constructor Description FastByteArrayOutputStream(byte[] pBuffer)
Creates aByteArrayOutputStream
with the given initial content.FastByteArrayOutputStream(int pSize)
Creates aByteArrayOutputStream
with the given initial buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.ByteArrayInputStream
createInputStream()
Creates aByteArrayInputStream
that reads directly from thisFastByteArrayOutputStream
's byte buffer.byte[]
toByteArray()
void
write(byte[] pBytes, int pOffset, int pLength)
void
write(int pByte)
void
writeTo(java.io.OutputStream pOut)
-
-
-
Constructor Detail
-
FastByteArrayOutputStream
public FastByteArrayOutputStream(int pSize)
Creates aByteArrayOutputStream
with the given initial buffer size.- Parameters:
pSize
- initial buffer size
-
FastByteArrayOutputStream
public FastByteArrayOutputStream(byte[] pBuffer)
Creates aByteArrayOutputStream
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 classjava.io.ByteArrayOutputStream
-
write
public void write(int pByte)
- Overrides:
write
in classjava.io.ByteArrayOutputStream
-
writeTo
public void writeTo(java.io.OutputStream pOut) throws java.io.IOException
- Overrides:
writeTo
in classjava.io.ByteArrayOutputStream
- Throws:
java.io.IOException
-
toByteArray
public byte[] toByteArray()
- Overrides:
toByteArray
in classjava.io.ByteArrayOutputStream
-
createInputStream
public java.io.ByteArrayInputStream createInputStream()
Creates aByteArrayInputStream
that 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.
-
-