Package com.twelvemonkeys.io
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 $
- Author:
- Harald Kuhr
-
Field Summary
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
-
Constructor Summary
ConstructorsConstructorDescriptionFastByteArrayOutputStream
(byte[] pBuffer) Creates aByteArrayOutputStream
with the given initial content.FastByteArrayOutputStream
(int pSize) Creates aByteArrayOutputStream
with the given initial buffer size. -
Method Summary
Modifier and TypeMethodDescriptionCreates aByteArrayInputStream
that reads directly from thisFastByteArrayOutputStream
's byte buffer.byte[]
void
write
(byte[] pBytes, int pOffset, int pLength) void
write
(int pByte) void
writeTo
(OutputStream pOut) Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toString, toString, toString, toString, writeBytes
Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Constructor Details
-
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 Details
-
write
public void write(byte[] pBytes, int pOffset, int pLength) - Overrides:
write
in classByteArrayOutputStream
-
write
public void write(int pByte) - Overrides:
write
in classByteArrayOutputStream
-
writeTo
- Overrides:
writeTo
in classByteArrayOutputStream
- Throws:
IOException
-
toByteArray
public byte[] toByteArray()- Overrides:
toByteArray
in classByteArrayOutputStream
-
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.
-