Class InputOutputByteStream
- java.lang.Object
-
- org.linuxforhealth.fhir.persistence.util.InputOutputByteStream
-
@NotThreadSafe public class InputOutputByteStream extends java.lang.Object
A byte buffer which supports both InputStream and OutputStream interfaces without needless copying of (potentially large) byte arrays. Not intended for multi-threaded access (no synchronization).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
InputOutputByteStream.ReshapeStrategy
Strategy for how we resize the buffer.
-
Constructor Summary
Constructors Constructor Description InputOutputByteStream(byte[] adoptBuffer, int offset)
Adopt a buffer which may already contain dataInputOutputByteStream(int initialCapacity)
Create a buffer with the given capacity and defaultInputOutputByteStream.ReshapeStrategy
InputOutputByteStream(int initialCapacity, InputOutputByteStream.ReshapeStrategy strat)
Create a buffer with a given capacity and override theInputOutputByteStream.ReshapeStrategy
InputOutputByteStream(java.nio.ByteBuffer bb)
Initialize the internal buffer by copying the contents of the given ByteBuffer (which can be read-only).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
getRawBuffer()
Get the underlying byte[] buffer at the current point in time.java.io.InputStream
inputStream()
Provide a new InputStream with its own dedicated position starting at 0 offsetjava.io.OutputStream
outputStream()
Return a new output stream backed by the byte buffer managed by this.void
reset()
Reset the offset to make the buffer appear empty.int
size()
How many bytes have been written to the byte bufferjava.nio.ByteBuffer
wrap()
Provides a wrapped version of the internal buffer.
-
-
-
Constructor Detail
-
InputOutputByteStream
public InputOutputByteStream(int initialCapacity)
Create a buffer with the given capacity and defaultInputOutputByteStream.ReshapeStrategy
-
InputOutputByteStream
public InputOutputByteStream(byte[] adoptBuffer, int offset)
Adopt a buffer which may already contain data- Parameters:
adoptBuffer
-offset
-
-
InputOutputByteStream
public InputOutputByteStream(java.nio.ByteBuffer bb)
Initialize the internal buffer by copying the contents of the given ByteBuffer (which can be read-only).- Parameters:
bb
-
-
InputOutputByteStream
public InputOutputByteStream(int initialCapacity, InputOutputByteStream.ReshapeStrategy strat)
Create a buffer with a given capacity and override theInputOutputByteStream.ReshapeStrategy
- Parameters:
initialCapacity
-strat
-
-
-
Method Detail
-
size
public int size()
How many bytes have been written to the byte buffer- Returns:
-
outputStream
public java.io.OutputStream outputStream()
Return a new output stream backed by the byte buffer managed by this.- Returns:
- Throws:
java.lang.IllegalStateException
- if called after the mode has been flipped to read.
-
inputStream
public java.io.InputStream inputStream()
Provide a new InputStream with its own dedicated position starting at 0 offset- Returns:
-
wrap
public java.nio.ByteBuffer wrap()
Provides a wrapped version of the internal buffer.- Returns:
- a read-only ByteBuffer.
-
reset
public void reset()
Reset the offset to make the buffer appear empty. Does not change the current length (capacity). Note that any streams currently being used to read the data will end.
-
getRawBuffer
public byte[] getRawBuffer()
Get the underlying byte[] buffer at the current point in time.- Returns:
-
-