Package jadex.common
Class BufferOutputStream
java.lang.Object
java.io.OutputStream
jadex.common.BufferOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new BufferOutputStream with a default initial size.BufferOutputStream(int capacity) Creates a new BufferOutputStream with the specified initial size. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckAndExpandCapacity(int reqcap) Checks if there is enough capacity for an operation and expands as necessary.voidclose()Since this is backed by a buffer, this does nothing.voidreset()Resets the buffer, all data lost.intsize()Returns the buffer size.toBuffer()Converts the buffer to a ByteBuffer.byte[]Converts the buffer to an appropriately sizes array.Converts the buffer to a direct ByteBuffer.voidwrite(byte[] arr, int off, int len) Writes the specified bytes from the byte array, starting at the provided offset.voidwrite(int b) Writes a byte to the stream.voidwriteBytes(byte[] arr) Writes a byte array to the stream.voidwriteTo(OutputStream os) Writes the stream content to an output stream..Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Field Details
-
buffer
protected byte[] buffer -
bufsize
protected int bufsize
-
-
Constructor Details
-
BufferOutputStream
public BufferOutputStream()Creates a new BufferOutputStream with a default initial size. -
BufferOutputStream
public BufferOutputStream(int capacity) Creates a new BufferOutputStream with the specified initial size.- Parameters:
capacity- The initial capacity, grows as necessary.
-
-
Method Details
-
write
public void write(int b) Writes a byte to the stream.- Specified by:
writein classOutputStream- Parameters:
b- The byte to write.
-
write
public void write(byte[] arr, int off, int len) Writes the specified bytes from the byte array, starting at the provided offset.- Overrides:
writein classOutputStream- Parameters:
arr- The array.off- The array offset..len- Number of bytes to write.
-
writeBytes
public void writeBytes(byte[] arr) Writes a byte array to the stream.- Parameters:
arr- the data.
-
writeTo
Writes the stream content to an output stream..- Parameters:
os- The output stream target.- Throws:
IOException- Thrown on IO issues.
-
reset
public void reset()Resets the buffer, all data lost. -
toByteArray
public byte[] toByteArray()Converts the buffer to an appropriately sizes array.- Returns:
- Stream content as an array.
-
toBuffer
Converts the buffer to a ByteBuffer.- Returns:
- Stream content as a ByteBuffer.
-
toDirectBuffer
Converts the buffer to a direct ByteBuffer.- Returns:
- Stream content as a direct ByteBuffer.
-
size
public int size()Returns the buffer size.- Returns:
- Buffer size.
-
close
Since this is backed by a buffer, this does nothing.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
checkAndExpandCapacity
protected void checkAndExpandCapacity(int reqcap) Checks if there is enough capacity for an operation and expands as necessary.- Parameters:
reqcap- The required capacity.
-