Interface MessageSource
public sealed interface MessageSource
A source of bytes that a
MessageReader reads from.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface -
Method Summary
Modifier and TypeMethodDescriptionReturns the buffer allocator used by this message source.buffer()Returns the read buffer of this message source.voidensureRemaining(int length) bytenextByte()Reads the nextbytewithout consuming it.intread(ByteBuffer buffer) Reads between 1 and remaining bytes into the given byte buffer.intreadAtLeast(ByteBuffer buffer, int length) Reads betweenlengthand remaining bytes into the given byte buffer.bytereadByte()Reads abyte.doubleReads adouble.floatReads afloat.intreadInt()Reads anint.intReads a 16-bit unsigned length value into anint.intreadLength32(MessageType type) Reads a 32-bit unsigned length value into anint.shortReads an 8-bit unsigned length value into ashort.longreadLong()Reads along.shortReads ashort.shortReads an unsigned byte into ashort.longreadUInt()Reads an unsigned int into along.intReads an unsigned short into anint.voidskip(int length) Skips the nextlengthbytes.longtransferTo(WritableByteChannel channel, long length) Transfers up tolengthbytes from this message source to the given channel.
-
Method Details
-
buffer
ByteBuffer buffer()Returns the read buffer of this message source.- Returns:
- the read buffer of this message source
-
allocator
BufferAllocator allocator()Returns the buffer allocator used by this message source.- Returns:
- the buffer allocator used by this message source
-
read
Reads between 1 and remaining bytes into the given byte buffer.- Parameters:
buffer- the byte buffer to read into- Returns:
- the actual number of bytes read, or
-1if the end of input has been reached - Throws:
IOException- if an I/O error occurs
-
readAtLeast
Reads betweenlengthand remaining bytes into the given byte buffer.- Parameters:
buffer- the byte buffer to read intolength- the minimum number of bytes to read- Returns:
- the actual number of bytes read (between
lengthandBuffer.remaining()) - Throws:
EOFException- if the end of input is reached beforelengthbytes have been readIOException- if an I/O error occurs
-
transferTo
Transfers up to
lengthbytes from this message source to the given channel.Fewer than
lengthbytes may be transferred if this message source reaches the end of input.- Parameters:
channel- the channel to write tolength- the number of bytes to transfer- Returns:
- the actual number of bytes transferred (between 0 and
length) - Throws:
IOException- if an I/O error occurs
-
ensureRemaining
Reads enough bytes from this message source for
buffer()to have at leastlengthbytes remaining.The number of bytes read is between 0 and
Buffer.capacity().- Parameters:
length- the minimum number of bytes thatbuffer()needs to have remaining- Throws:
EOFException- if the end of input is reached beforebuffer()haslengthbytes remainingIOException- if an I/O error occurs
-
skip
Skips the nextlengthbytes.- Parameters:
length- the number of bytes to skip- Throws:
EOFException- if the end of input is reached beforelengthbytes have been skippedIOException- if an I/O error occurs
-
nextByte
Reads the next
bytewithout consuming it.Consecutive calls to this method will return the same result.
- Returns:
- the
byteread - Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readByte
Reads abyte.- Returns:
- the
byteread - Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readShort
Reads ashort.- Returns:
- the
shortread - Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readInt
Reads anint.- Returns:
- the
intread - Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readLong
Reads along.- Returns:
- the
longread - Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readFloat
Reads afloat.- Returns:
- the
floatread - Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readDouble
Reads adouble.- Returns:
- the
doubleread - Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readUByte
Reads an unsigned byte into ashort.- Returns:
- the unsigned byte read
- Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readUShort
Reads an unsigned short into anint.- Returns:
- the unsigned short read
- Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readUInt
Reads an unsigned int into along.- Returns:
- the unsigned int read
- Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readLength8
Reads an 8-bit unsigned length value into a
short.This method is equivalent to
readUByte().- Returns:
- the length value read
- Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readLength16
Reads a 16-bit unsigned length value into an
int.This method is equivalent to
readUShort().- Returns:
- the length value read
- Throws:
EOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-
readLength32
Reads a 32-bit unsigned length value into anint.- Parameters:
type- the type of value whose length to read (used in exception message)- Returns:
- the length value read
- Throws:
MxPackException.SizeLimitExceeded- if the value is greater thanInteger.MAX_VALUEEOFException- if the end of input is reached before the value has been readIOException- if an I/O error occurs
-