Package org.agrona.io
Class DirectBufferOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.agrona.io.DirectBufferOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class DirectBufferOutputStream extends java.io.OutputStream
OutputStream
that wraps an underlyingMutableDirectBuffer
.
-
-
Field Summary
Fields Modifier and Type Field Description private MutableDirectBuffer
buffer
private int
length
private int
offset
private int
position
-
Constructor Summary
Constructors Constructor Description DirectBufferOutputStream()
Default constructor.DirectBufferOutputStream(MutableDirectBuffer buffer)
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MutableDirectBuffer
buffer()
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.
-
-
-
Field Detail
-
buffer
private MutableDirectBuffer buffer
-
offset
private int offset
-
length
private int length
-
position
private int position
-
-
Constructor Detail
-
DirectBufferOutputStream
public DirectBufferOutputStream()
Default constructor.
-
DirectBufferOutputStream
public DirectBufferOutputStream(MutableDirectBuffer buffer)
Constructs output stream wrapping the given buffer.- Parameters:
buffer
- to wrap.
-
DirectBufferOutputStream
public DirectBufferOutputStream(MutableDirectBuffer buffer, int offset, int length)
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 Detail
-
wrap
public void wrap(MutableDirectBuffer buffer)
Wrap the buffer.- Parameters:
buffer
- to wrap.
-
wrap
public void wrap(MutableDirectBuffer buffer, int offset, int length)
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
public MutableDirectBuffer 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 classjava.io.OutputStream
- Parameters:
b
- to be written.- Throws:
java.lang.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 classjava.io.OutputStream
- Parameters:
srcBytes
- to writesrcOffset
- at which to begin reading bytes from the srcBytes.length
- of the srcBytes to read.- Throws:
java.lang.IllegalStateException
- if insufficient capacity remains in the buffer.
-
write
public void write(byte[] srcBytes)
Write a byte[] to the buffer.- Overrides:
write
in classjava.io.OutputStream
- Parameters:
srcBytes
- to write- Throws:
java.lang.IllegalStateException
- if insufficient capacity remains in the buffer.
-
flush
public void flush()
Override to removeIOException
. This method does nothing.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
-
close
public void close()
Override to removeIOException
. This method does nothing.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
-
-