public class DirectBufferDataInput extends Object implements DataInput
DataInput
description including throwing checked exception on end of file. It adds few more methods to read strings without
allocations.
Note about byte ordering: by default, this class conforms to DataInput contract and uses
ByteOrder.BIG_ENDIAN byte order which allows it to read data produced by JDK DataOutput
implementations. Agrona buffers use ByteOrder.LITTLE_ENDIAN (unless overridden). Use
byteOrder(ByteOrder) method to switch between JDK and Agrona compatibility.
| Constructor and Description |
|---|
DirectBufferDataInput(DirectBuffer buffer)
Wrap given
DirectBuffer. |
DirectBufferDataInput(DirectBuffer buffer,
int offset,
int length)
Wrap given
DirectBuffer. |
| Modifier and Type | Method and Description |
|---|---|
void |
byteOrder(ByteOrder byteOrder)
Sets the byte order.
|
boolean |
readBoolean() |
byte |
readByte() |
char |
readChar() |
double |
readDouble() |
float |
readFloat() |
void |
readFully(byte[] destination) |
void |
readFully(byte[] destination,
int destinationOffset,
int length) |
int |
readInt() |
String |
readLine() |
int |
readLine(Appendable appendable)
Reads the next line of text from the input stream.
|
long |
readLong() |
short |
readShort() |
String |
readStringAscii()
Reads in a string that has been encoded using ASCII format by
MutableDirectBuffer.putStringAscii(int, CharSequence). |
int |
readStringAscii(Appendable appendable)
Get a String from bytes encoded in ASCII format that is length prefixed and append to an
Appendable. |
String |
readStringUTF8()
Reads in a string that has been encoded using UTF-8 format by
MutableDirectBuffer.putStringUtf8(int, String). |
int |
readUnsignedByte() |
int |
readUnsignedShort() |
String |
readUTF() |
int |
remaining()
Return the number of bytes remaining in the buffer.
|
int |
skipBytes(int n) |
void |
wrap(DirectBuffer buffer)
Wrap given
DirectBuffer. |
void |
wrap(DirectBuffer buffer,
int offset,
int length)
Wrap given
DirectBuffer. |
public DirectBufferDataInput(DirectBuffer buffer)
DirectBuffer.buffer - to wrap.public DirectBufferDataInput(DirectBuffer buffer, int offset, int length)
DirectBuffer.buffer - to wrap.offset - into the buffer.length - in bytes.public void wrap(DirectBuffer buffer)
DirectBuffer.buffer - to wrap.public void wrap(DirectBuffer buffer, int offset, int length)
DirectBuffer.buffer - to wrap.offset - into the buffer.length - in bytes.public void byteOrder(ByteOrder byteOrder)
DataInput contract and uses
ByteOrder.BIG_ENDIAN which allows it to read data produced by JDK DataOutput
implementations. Agrona buffers use ByteOrder.LITTLE_ENDIAN (unless overridden).
Use this method to switch compatibility between these two worlds.byteOrder - of the underlying buffer.public int remaining()
public void readFully(byte[] destination)
throws EOFException
readFully in interface DataInputEOFExceptionpublic void readFully(byte[] destination,
int destinationOffset,
int length)
throws EOFException
readFully in interface DataInputEOFExceptionpublic boolean readBoolean()
throws EOFException
readBoolean in interface DataInputEOFExceptionpublic byte readByte()
throws EOFException
readByte in interface DataInputEOFExceptionpublic int readUnsignedByte()
throws EOFException
readUnsignedByte in interface DataInputEOFExceptionpublic short readShort()
throws EOFException
readShort in interface DataInputEOFExceptionpublic int readUnsignedShort()
throws EOFException
readUnsignedShort in interface DataInputEOFExceptionpublic char readChar()
throws EOFException
readChar in interface DataInputEOFExceptionpublic int readInt()
throws EOFException
readInt in interface DataInputEOFExceptionpublic long readLong()
throws EOFException
readLong in interface DataInputEOFExceptionpublic float readFloat()
throws EOFException
readFloat in interface DataInputEOFExceptionpublic double readDouble()
throws EOFException
readDouble in interface DataInputEOFExceptionpublic String readLine() throws IOException
readLine in interface DataInputIOExceptionpublic int readLine(Appendable appendable) throws IOException
DataInput.readLine().appendable - to append the chars to.IOException - propagated from Appendable.append(char).public String readUTF() throws EOFException
readUTF in interface DataInputEOFExceptionpublic String readStringUTF8()
MutableDirectBuffer.putStringUtf8(int, String).
This is a thin wrapper over DirectBuffer.getStringUtf8(int, ByteOrder). Honours byte order set by
byteOrder(ByteOrder).
public String readStringAscii()
MutableDirectBuffer.putStringAscii(int, CharSequence).
This is a thin wrapper over DirectBuffer.getStringAscii(int, ByteOrder). Honours byte order set by
byteOrder(ByteOrder)
public int readStringAscii(Appendable appendable)
Appendable.
This is a thin wrapper over DirectBuffer.getStringAscii(int, Appendable, ByteOrder). Honours byte order
set by byteOrder(ByteOrder).appendable - to append the chars to.Copyright © 2014-2022 Real Logic Limited. All Rights Reserved.