Interface MessageSource


public sealed interface MessageSource
A source of bytes that a MessageReader reads from.
  • 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

      int read(ByteBuffer buffer) throws IOException
      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 -1 if the end of input has been reached
      Throws:
      IOException - if an I/O error occurs
    • readAtLeast

      int readAtLeast(ByteBuffer buffer, int length) throws IOException
      Reads between length and remaining bytes into the given byte buffer.
      Parameters:
      buffer - the byte buffer to read into
      length - the minimum number of bytes to read
      Returns:
      the actual number of bytes read (between length and Buffer.remaining())
      Throws:
      EOFException - if the end of input is reached before length bytes have been read
      IOException - if an I/O error occurs
    • transferTo

      long transferTo(WritableByteChannel channel, long length) throws IOException

      Transfers up to length bytes from this message source to the given channel.

      Fewer than length bytes may be transferred if this message source reaches the end of input.

      Parameters:
      channel - the channel to write to
      length - 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

      void ensureRemaining(int length) throws IOException

      Reads enough bytes from this message source for buffer() to have at least length bytes remaining.

      The number of bytes read is between 0 and Buffer.capacity().

      Parameters:
      length - the minimum number of bytes that buffer() needs to have remaining
      Throws:
      EOFException - if the end of input is reached before buffer() has length bytes remaining
      IOException - if an I/O error occurs
    • skip

      void skip(int length) throws IOException
      Skips the next length bytes.
      Parameters:
      length - the number of bytes to skip
      Throws:
      EOFException - if the end of input is reached before length bytes have been skipped
      IOException - if an I/O error occurs
    • nextByte

      byte nextByte() throws IOException

      Reads the next byte without consuming it.

      Consecutive calls to this method will return the same result.

      Returns:
      the byte read
      Throws:
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs
    • readByte

      byte readByte() throws IOException
      Reads a byte.
      Returns:
      the byte read
      Throws:
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs
    • readShort

      short readShort() throws IOException
      Reads a short.
      Returns:
      the short read
      Throws:
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs
    • readInt

      int readInt() throws IOException
      Reads an int.
      Returns:
      the int read
      Throws:
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs
    • readLong

      long readLong() throws IOException
      Reads a long.
      Returns:
      the long read
      Throws:
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs
    • readFloat

      float readFloat() throws IOException
      Reads a float.
      Returns:
      the float read
      Throws:
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs
    • readDouble

      double readDouble() throws IOException
      Reads a double.
      Returns:
      the double read
      Throws:
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs
    • readUByte

      short readUByte() throws IOException
      Reads an unsigned byte into a short.
      Returns:
      the unsigned byte read
      Throws:
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs
    • readUShort

      int readUShort() throws IOException
      Reads an unsigned short into an int.
      Returns:
      the unsigned short read
      Throws:
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs
    • readUInt

      long readUInt() throws IOException
      Reads an unsigned int into a long.
      Returns:
      the unsigned int read
      Throws:
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs
    • readLength8

      short readLength8() throws IOException

      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 read
      IOException - if an I/O error occurs
    • readLength16

      int readLength16() throws IOException

      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 read
      IOException - if an I/O error occurs
    • readLength32

      int readLength32(MessageType type) throws IOException
      Reads a 32-bit unsigned length value into an int.
      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 than Integer.MAX_VALUE
      EOFException - if the end of input is reached before the value has been read
      IOException - if an I/O error occurs