Class InStream


  • public class InStream
    extends Object
    • Constructor Summary

      Constructors 
      Constructor Description
      InStream​(byte[] data)
      Creates a new buffered input stream based on the given byte array.
      InStream​(byte[] data, int offset, int length)
      Creates a new buffered input stream based on the section in the given byte array.
      InStream​(byte[] data, int offset, int length, Duration readDuration)
      Creates a new buffered input stream based on the section in the given byte array.
      InStream​(byte[] data, Duration readDuration)
      Creates a new buffered input stream based on the given byte array.
    • Constructor Detail

      • InStream

        public InStream​(byte[] data)
        Creates a new buffered input stream based on the given byte array. Calls InStream(data, 0, data.length, null).
        Parameters:
        data - The byte buffer
        See Also:
        InStream(byte[], int, int)
      • InStream

        public InStream​(byte[] data,
                        Duration readDuration)
        Creates a new buffered input stream based on the given byte array. Calls InStream(data, 0, data.length, readDuration).
        Parameters:
        data - The byte buffer
        readDuration - The duration it took to read the given buffer
        See Also:
        InStream(byte[], int, int, Duration)
      • InStream

        public InStream​(byte[] data,
                        int offset,
                        int length)
        Creates a new buffered input stream based on the section in the given byte array.
        Parameters:
        data - The byte buffer
        offset - The starting offset
        length - The amount of bytes available
        See Also:
        InStream(byte[], int, int, Duration)
      • InStream

        public InStream​(byte[] data,
                        int offset,
                        int length,
                        Duration readDuration)
        Creates a new buffered input stream based on the section in the given byte array.
        Parameters:
        data - The byte buffer
        offset - The starting offset
        length - The amount of bytes available
        readDuration - The duration it took to read the given buffer
    • Method Detail

      • readBoolean

        public boolean readBoolean()
        Reads a boolean value from the stream. The boolean is true when the read byte is not zero.
        Returns:
        The read boolean
      • readByte

        public byte readByte()
        Reads a signed byte from the stream.
        Returns:
        The read byte.
      • readChar

        public char readChar()
        Reads a character from the stream.
        Returns:
        The read character.
      • readFully

        public void readFully​(byte[] b)
        Fills the given byte array with data read from the stream.
        Parameters:
        b - The byte buffer to copy the data to.
      • readFully

        public void readFully​(byte[] b,
                              int off,
                              int len)
        Fills the given section of the byte array with data read from the stream.
        Parameters:
        b - The byte buffer to copy the data to.
        off - The starting offset.
        len - The amount of bytes to copy.
      • readFully

        public byte[] readFully​(int length)
        Reads length bytes into a new byte array.
        Parameters:
        length - The amount of bytes to read
        Returns:
        The read bytes.
      • readInt

        public int readInt()
        Reads an integer from the stream.
        Returns:
        The read integer.
      • readLong

        public long readLong()
        Reads a long from the stream.
        Returns:
        The read long.
      • readShort

        public short readShort()
        Reads a short from the stream.
        Returns:
        The read short.
      • readUnsignedByte

        public int readUnsignedByte()
        Reads an unsigned byte from the stream.
        Returns:
        The read byte.
      • readUnsignedShort

        public int readUnsignedShort()
        Reads an unsigned short from the stream.
        Returns:
        The read short.
      • skipBytes

        public int skipBytes​(int n)
        Skips the next n bytes on the stream.
        Parameters:
        n - The amount of bytes to skip
        Returns:
        The actual amount of bytes skipped.
      • moveBack

        public void moveBack​(int n)
        Moves the read pointer back with n position. This method cannot be combined with mark() on the same stream as this method assumes the marked position to be 0.
        Parameters:
        n - The amount of bytes to 'unread'
        See Also:
        mark()
      • available

        public int available()
        Calculates the amount of bytes still remaining to read on the stream.
        Returns:
        The amount of readable bytes.
      • readString

        public String readString​(int length)
        Reads a string from the stream.
        Parameters:
        length - The amount of characters in the string
        Returns:
        The read string.
      • mark

        public void mark()
        Marks the current position.
      • resetToMark

        public void resetToMark()
        Returns to the last marked position with mark() or 0 if no mark has happened before.
      • getReadDuration

        public Optional<Duration> getReadDuration()
        Gets the duration it took to read this message.
        Returns:
        The duration it took or Optional.empty() if unknown