Class ConfInputStream

Object
InputStream
ByteArrayInputStream
com.tailf.proto.ConfInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class ConfInputStream extends ByteArrayInputStream
Provides a stream for decoding E terms from external format.

Note that this class is not synchronized, if you need synchronization you must provide it yourself.

  • Constructor Details

    • ConfInputStream

      public ConfInputStream(byte[] buf)
      Create a stream from a buffer containing encoded E terms.
    • ConfInputStream

      public ConfInputStream(byte[] buf, int offset, int length)
      Create a stream from a buffer containing encoded E terms at the given offset and length.
  • Method Details

    • getPos

      public int getPos()
      Get the current position in the stream.
      Returns:
      the current position in the stream.
    • setPos

      public int setPos(int pos)
      Set the current position in the stream.
      Parameters:
      pos - the position to move to in the stream. If pos indicates a position beyond the end of the stream, the position is move to the end of the stream instead. If pos is negative, the position is moved to the beginning of the stream instead.
      Returns:
      the previous position in the stream.
    • readN

      public int readN(byte[] buf) throws ConfEDecodeException
      Read an array of bytes from the stream. The method reads at most buf.length bytes from the input stream.
      Returns:
      the number of bytes read.
      Throws:
      ConfEDecodeException - if the next byte cannot be read.
    • peek

      public int peek() throws ConfEDecodeException
      Look ahead one position in the stream without consuming the byte found there.
      Returns:
      the next byte in the stream, as an integer.
      Throws:
      ConfEDecodeException - if the next byte cannot be read.
    • read1

      public int read1() throws ConfEDecodeException
      Read a one byte integer from the stream.
      Returns:
      the byte read, as an integer.
      Throws:
      ConfEDecodeException - if the next byte cannot be read.
    • read2BE

      public int read2BE() throws ConfEDecodeException
      Read a two byte big endian integer from the stream.
      Returns:
      the bytes read, converted from big endian to an integer.
      Throws:
      ConfEDecodeException - if the next byte cannot be read.
    • read4BE

      public int read4BE() throws ConfEDecodeException
      Read a four byte big endian integer from the stream.
      Returns:
      the bytes read, converted from big endian to an integer.
      Throws:
      ConfEDecodeException - if the next byte cannot be read.
    • read2LE

      public int read2LE() throws ConfEDecodeException
      Read a two byte little endian integer from the stream.
      Returns:
      the bytes read, converted from little endian to an integer.
      Throws:
      ConfEDecodeException - if the next byte cannot be read.
    • read4LE

      public int read4LE() throws ConfEDecodeException
      Read a four byte little endian integer from the stream.
      Returns:
      the bytes read, converted from little endian to an integer.
      Throws:
      ConfEDecodeException - if the next byte cannot be read.
    • readLE

      public long readLE(int n) throws ConfEDecodeException
      Read a little endian integer from the stream.
      Parameters:
      n - the number of bytes to read
      Returns:
      the bytes read, converted from little endian to an integer.
      Throws:
      ConfEDecodeException - if the next byte cannot be read.
    • readBE

      public long readBE(int n) throws ConfEDecodeException
      Read a big endian integer from the stream.
      Parameters:
      n - the number of bytes to read
      Returns:
      the bytes read, converted from big endian to an integer.
      Throws:
      ConfEDecodeException - if the next byte cannot be read.
    • read_boolean

      public boolean read_boolean() throws ConfEDecodeException
      Read an E atom from the stream and interpret the value as a boolean.
      Returns:
      true if the atom at the current position in the stream contains the value 'true' (ignoring case), false otherwise.
      Throws:
      ConfEDecodeException - if the next term in the stream is not an atom.
    • read_atom

      public String read_atom() throws ConfEDecodeException
      Read an E atom from the stream.
      Returns:
      a String containing the value of the atom.
      Throws:
      ConfEDecodeException - if the next term in the stream is not an atom.
    • read_binary

      public byte[] read_binary() throws ConfEDecodeException
      Read an E binary from the stream.
      Returns:
      a byte array containing the value of the binary.
      Throws:
      ConfEDecodeException - if the next term in the stream is not a binary.
    • read_float

      public float read_float() throws ConfEDecodeException
      Read an E float from the stream.
      Returns:
      the float value.
      Throws:
      ConfEDecodeException - if the next term in the stream is not a float.
    • read_double

      public double read_double() throws ConfEDecodeException
      Read an E float from the stream.
      Returns:
      the float value, as a double.
      Throws:
      ConfEDecodeException - if the next term in the stream is not a float.
    • read_byte

      public byte read_byte() throws ConfEDecodeException
      Read one byte from the stream.
      Returns:
      the byte read.
      Throws:
      ConfEDecodeException - if the next byte cannot be read.
    • read_char

      public char read_char() throws ConfEDecodeException
      Read a character from the stream.
      Returns:
      the character value.
      Throws:
      ConfEDecodeException - if the next term in the stream is not an integer that can be represented as a char.
    • read_uint

      public int read_uint() throws ConfEDecodeException
      Read an unsigned integer from the stream.
      Returns:
      the integer value.
      Throws:
      ConfEDecodeException - if the next term in the stream can not be represented as a positive integer.
    • read_int

      public int read_int() throws ConfEDecodeException
      Read an integer from the stream.
      Returns:
      the integer value.
      Throws:
      ConfEDecodeException - if the next term in the stream can not be represented as an integer.
    • read_ushort

      public short read_ushort() throws ConfEDecodeException
      Read an unsigned short from the stream.
      Returns:
      the short value.
      Throws:
      ConfEDecodeException - if the next term in the stream can not be represented as a positive short.
    • read_short

      public short read_short() throws ConfEDecodeException
      Read a short from the stream.
      Returns:
      the short value.
      Throws:
      ConfEDecodeException - if the next term in the stream can not be represented as a short.
    • read_ulong

      public long read_ulong() throws ConfEDecodeException
      Read an unsigned long from the stream.
      Returns:
      the long value.
      Throws:
      ConfEDecodeException - if the next term in the stream can not be represented as a positive long.
    • read_long

      public long read_long() throws ConfEDecodeException
      Read a long from the stream.
      Returns:
      the long value.
      Throws:
      ConfEDecodeException - if the next term in the stream can not be represented as a long.
    • read_long

      public long read_long(boolean unsigned) throws ConfEDecodeException
      Throws:
      ConfEDecodeException
    • read_long_big

      public ConfEObject read_long_big() throws ConfEDecodeException
      Throws:
      ConfEDecodeException
    • read_big

      public BigInteger read_big() throws ConfEDecodeException
      Throws:
      ConfEDecodeException
    • read_list_head

      public int read_list_head() throws ConfEDecodeException
      Read a list header from the stream.
      Returns:
      the arity of the list.
      Throws:
      ConfEDecodeException - if the next term in the stream is not a list.
    • read_tuple_head

      public int read_tuple_head() throws ConfEDecodeException
      Read a tuple header from the stream.
      Returns:
      the arity of the tuple.
      Throws:
      ConfEDecodeException - if the next term in the stream is not a tuple.
    • read_nil

      public int read_nil() throws ConfEDecodeException
      Read an empty list from the stream.
      Returns:
      zero (the arity of the list).
      Throws:
      ConfEDecodeException - if the next term in the stream is not an empty list.
    • read_ref

      public ConfERef read_ref() throws ConfEDecodeException
      Read an E reference from the stream.
      Returns:
      the value of the reference
      Throws:
      ConfEDecodeException - if the next term in the stream is not an E reference.
    • read_pid

      public ConfEPid read_pid() throws ConfEDecodeException
      Read an E pid from the stream.
      Returns:
      the value of the pid
      Throws:
      ConfEDecodeException - if the next term in the stream is not an E pid.
    • read_string

      public String read_string() throws ConfEDecodeException
      Read a string from the stream.
      Returns:
      the value of the string.
      Throws:
      ConfEDecodeException - if the next term in the stream is not a string.
    • read_any

      public ConfEObject read_any() throws ConfEDecodeException
      Read an arbitrary E term from the stream.
      Returns:
      the E term.
      Throws:
      ConfEDecodeException - if the stream does not contain a known E type at the next position.