Package org.agrona.io
Class DirectBufferOutputStream
java.lang.Object
java.io.OutputStream
org.agrona.io.DirectBufferOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
OutputStream
that wraps an underlying MutableDirectBuffer
.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.Constructs output stream wrapping the given buffer.DirectBufferOutputStream
(MutableDirectBuffer buffer, int offset, int length) Constructs output stream wrapping the given buffer at an offset. -
Method Summary
Modifier and TypeMethodDescriptionbuffer()
The underlying buffer being wrapped.void
close()
Override to removeIOException
.void
flush()
Override to removeIOException
.int
length()
The length of the underlying buffer to use.int
offset()
The offset within the underlying buffer at which to start.int
position()
The position in the buffer from the offset up to which has been written.void
wrap
(MutableDirectBuffer buffer) Wrap the buffer.void
wrap
(MutableDirectBuffer buffer, int offset, int length) Wrap the buffer at an offset.void
write
(byte[] srcBytes) Write a byte[] to the buffer.void
write
(byte[] srcBytes, int srcOffset, int length) Write a byte[] to the buffer.void
write
(int b) Write a byte to buffer.Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
buffer
-
offset
private int offset -
length
private int length -
position
private int position
-
-
Constructor Details
-
DirectBufferOutputStream
public DirectBufferOutputStream()Default constructor. -
DirectBufferOutputStream
Constructs output stream wrapping the given buffer.- Parameters:
buffer
- to wrap.
-
DirectBufferOutputStream
Constructs output stream wrapping the given buffer at an offset.- Parameters:
buffer
- to wrap.offset
- in the buffer.length
- size in bytes to wrap.
-
-
Method Details
-
wrap
Wrap the buffer.- Parameters:
buffer
- to wrap.
-
wrap
Wrap the buffer at an offset.- Parameters:
buffer
- to wrap.offset
- in the buffer.length
- size in bytes to wrap.
-
position
public int position()The position in the buffer from the offset up to which has been written.- Returns:
- the position in the buffer from the offset up to which has been written.
-
offset
public int offset()The offset within the underlying buffer at which to start.- Returns:
- offset within the underlying buffer at which to start.
-
buffer
The underlying buffer being wrapped.- Returns:
- the underlying buffer being wrapped.
-
length
public int length()The length of the underlying buffer to use.- Returns:
- length of the underlying buffer to use.
-
write
public void write(int b) Write a byte to buffer.- Specified by:
write
in classOutputStream
- Parameters:
b
- to be written.- Throws:
IllegalStateException
- if insufficient capacity remains in the buffer.
-
write
public void write(byte[] srcBytes, int srcOffset, int length) Write a byte[] to the buffer.- Overrides:
write
in classOutputStream
- Parameters:
srcBytes
- to writesrcOffset
- at which to begin reading bytes from the srcBytes.length
- of the srcBytes to read.- Throws:
IllegalStateException
- if insufficient capacity remains in the buffer.
-
write
public void write(byte[] srcBytes) Write a byte[] to the buffer.- Overrides:
write
in classOutputStream
- Parameters:
srcBytes
- to write- Throws:
IllegalStateException
- if insufficient capacity remains in the buffer.
-
flush
public void flush()Override to removeIOException
. This method does nothing.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
-
close
public void close()Override to removeIOException
. This method does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
-