Package org.fusesource.hawtbuf
Class BufferOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.fusesource.hawtbuf.BufferOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public final class BufferOutputStream extends java.io.OutputStream
Very similar to the java.io.ByteArrayOutputStream but this version is not thread safe and the resulting data is returned in a Buffer to avoid an extra byte[] allocation. It also does not re-grow it's internal buffer.
-
-
Constructor Summary
Constructors Constructor Description BufferOutputStream(byte[] buffer)
BufferOutputStream(int size)
BufferOutputStream(Buffer data)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkCapacity(int minimumCapacity)
Ensures the the buffer has at least the minimumCapacity specified.Buffer
getNextBuffer(int len)
void
reset()
int
size()
Buffer
toBuffer()
byte[]
toByteArray()
void
write(byte[] b, int off, int len)
void
write(int b)
-
-
-
Constructor Detail
-
BufferOutputStream
public BufferOutputStream(int size)
-
BufferOutputStream
public BufferOutputStream(byte[] buffer)
-
BufferOutputStream
public BufferOutputStream(Buffer data)
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOException
- Specified by:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
getNextBuffer
public Buffer getNextBuffer(int len) throws java.io.IOException
- Throws:
java.io.IOException
-
checkCapacity
private void checkCapacity(int minimumCapacity) throws java.io.IOException
Ensures the the buffer has at least the minimumCapacity specified.- Parameters:
i
-- Throws:
java.io.EOFException
java.io.IOException
-
reset
public void reset()
-
toBuffer
public Buffer toBuffer()
-
toByteArray
public byte[] toByteArray()
-
size
public int size()
-
-