Class BinaryInput

java.lang.Object
org.graalvm.nativebridge.BinaryInput

public abstract class BinaryInput extends Object
A buffer used by the BinaryMarshaller to unmarshal parameters and results passed by value.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final int
     
    protected int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract ByteBuffer
    asByteBuffer(int len)
    Returns a read only ByteBuffer backed by the BinaryInput internal buffer.
    create(byte[] buffer)
    Creates a new buffer backed by a byte array.
    create(byte[] buffer, int length)
    Creates a new buffer backed by a byte array only up to a given length.
    create(org.graalvm.nativeimage.c.type.CCharPointer address, int length)
    Creates a new buffer wrapping an off-heap memory segment starting at an address having length bytes.
    abstract int
    Reads a single byte.
    final void
    read(boolean[] b, int off, int len)
    Reads len bytes into a boolean array starting at offset off.
    abstract void
    read(byte[] b, int off, int len)
    Reads len bytes into a byte array starting at offset off.
    final void
    read(char[] b, int off, int len)
    Reads len chars into a char array starting at offset off.
    final void
    read(double[] b, int off, int len)
    Reads len doubles into a double array starting at offset off.
    final void
    read(float[] b, int off, int len)
    Reads len floats into a float array starting at offset off.
    final void
    read(int[] b, int off, int len)
    Reads len ints into an int array starting at offset off.
    final void
    read(long[] b, int off, int len)
    Reads len longs into a long array starting at offset off.
    final void
    read(short[] b, int off, int len)
    Reads len shorts into a short array starting at offset off.
    final boolean
    Reads a single byte and returns true if that byte is non-zero, false if that byte is zero.
    final byte
    Reads and returns a single byte.
    final char
    Reads two bytes and returns a char value.
    final double
    Reads eight bytes and returns a double value.
    final float
    Reads four bytes and returns a float value.
    final int
    Reads four bytes and returns an int value.
    final long
    Reads eight bytes and returns a long value.
    final short
    Reads two bytes and returns a short value.
    final Object
    Reads a single value, using the data type encoded in the marshalled data.
    final String
    Reads a string using a modified UTF-8 encoding in a machine-independent manner.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • length

      protected final int length
    • pos

      protected int pos
  • Method Details

    • readBoolean

      public final boolean readBoolean() throws IndexOutOfBoundsException
      Reads a single byte and returns true if that byte is non-zero, false if that byte is zero.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read.
    • readByte

      public final byte readByte() throws IndexOutOfBoundsException
      Reads and returns a single byte.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read.
    • readShort

      public final short readShort() throws IndexOutOfBoundsException
      Reads two bytes and returns a short value.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read.
    • readChar

      public final char readChar() throws IndexOutOfBoundsException
      Reads two bytes and returns a char value.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read.
    • readInt

      public final int readInt() throws IndexOutOfBoundsException
      Reads four bytes and returns an int value.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read.
    • readLong

      public final long readLong() throws IndexOutOfBoundsException
      Reads eight bytes and returns a long value.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read.
    • readFloat

      public final float readFloat() throws IndexOutOfBoundsException
      Reads four bytes and returns a float value. It does this by reading an int value and converting the int value to a float using Float.intBitsToFloat(int).
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read.
    • readDouble

      public final double readDouble() throws IndexOutOfBoundsException
      Reads eight bytes and returns a double value. It does this by reading a long value and converting the long value to a double using Double.longBitsToDouble(long).
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read.
    • read

      public abstract int read()
      Reads a single byte. The byte value is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned.
    • read

      public abstract void read(byte[] b, int off, int len) throws IndexOutOfBoundsException
      Reads len bytes into a byte array starting at offset off.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read
    • readUTF

      Reads a string using a modified UTF-8 encoding in a machine-independent manner.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read.
      IllegalArgumentException - if the bytes do not represent a valid modified UTF-8 encoding of a string.
    • readTypedValue

      public final Object readTypedValue() throws IndexOutOfBoundsException, IllegalArgumentException
      Reads a single value, using the data type encoded in the marshalled data.
      Returns:
      The read value, such as a boxed Java primitive, a String, a null, or an array of these types.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read.
      IllegalArgumentException - when the marshaled type is not supported or if the bytes do not represent a valid modified UTF-8 encoding of a string.
    • read

      public final void read(boolean[] b, int off, int len)
      Reads len bytes into a boolean array starting at offset off.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read
    • read

      public final void read(short[] b, int off, int len)
      Reads len shorts into a short array starting at offset off.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read
    • read

      public final void read(char[] b, int off, int len)
      Reads len chars into a char array starting at offset off.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read
    • read

      public final void read(int[] b, int off, int len)
      Reads len ints into an int array starting at offset off.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read
    • read

      public final void read(long[] b, int off, int len)
      Reads len longs into a long array starting at offset off.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read
    • read

      public final void read(float[] b, int off, int len)
      Reads len floats into a float array starting at offset off.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read
    • read

      public final void read(double[] b, int off, int len)
      Reads len doubles into a double array starting at offset off.
      Throws:
      IndexOutOfBoundsException - if there are not enough bytes to read
    • asByteBuffer

      public abstract ByteBuffer asByteBuffer(int len)
      Returns a read only ByteBuffer backed by the BinaryInput internal buffer. The content of the buffer will start at the BinaryInput's current position. The buffer's capacity and limit will be len, its position will be zero, its mark will be undefined, and its byte order will be BIG_ENDIAN. After a successful call, the BinaryInput's current position is incremented by the len.
      Throws:
      IndexOutOfBoundsException - if the BinaryInput has not enough remaining bytes.
    • create

      public static BinaryInput create(byte[] buffer)
      Creates a new buffer backed by a byte array.
    • create

      public static BinaryInput create(byte[] buffer, int length)
      Creates a new buffer backed by a byte array only up to a given length.
    • create

      public static BinaryInput create(org.graalvm.nativeimage.c.type.CCharPointer address, int length)
      Creates a new buffer wrapping an off-heap memory segment starting at an address having length bytes.