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.-
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.voidclose()Override to removeIOException.voidflush()Override to removeIOException.intlength()The length of the underlying buffer to use.intoffset()The offset within the underlying buffer at which to start.intposition()The position in the buffer from the offset up to which has been written.voidwrap(MutableDirectBuffer buffer) Wrap the buffer.voidwrap(MutableDirectBuffer buffer, int offset, int length) Wrap the buffer at an offset.voidwrite(byte[] srcBytes) Write a byte[] to the buffer.voidwrite(byte[] srcBytes, int srcOffset, int length) Write a byte[] to the buffer.voidwrite(int b) Write a byte to buffer.Methods inherited from class java.io.OutputStream
nullOutputStream
-
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:
writein 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:
writein 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:
writein 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:
flushin interfaceFlushable- Overrides:
flushin classOutputStream
-
close
public void close()Override to removeIOException. This method does nothing.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream
-