Пример #1
0
  public static EObject read(EInputStream buf) throws IOException {
    final int arity = buf.read_list_head();
    EObject[] elems;
    EObject tail;
    if (arity > 0) {
      elems = new EObject[arity];
      for (int i = 0; i < arity; i++) {
        elems[i] = buf.read_any();
      }
      /* discard the terminating nil (empty list) or read tail */
      if (buf.peek1() == EExternal.nilTag) {
        buf.read_nil();
        tail = ERT.NIL;
      } else {
        tail = buf.read_any();
      }

      EObject res = tail;
      for (int i = arity - 1; i >= 0; i--) {
        res = res.cons(elems[i]);
      }

      return res;
    } else {
      return ERT.NIL;
    }
  }
Пример #2
0
  /**
   * Read a compressed term from the stream
   *
   * @return the resulting uncompressed term.
   * @exception IOException if the next term in the stream is not a compressed term.
   */
  public EObject read_compressed() throws IOException {
    final int tag = read1skip_version();

    if (tag != EExternal.compressedTag) {
      throw new IOException(
          "Wrong tag encountered, expected " + EExternal.compressedTag + ", got " + tag);
    }
    final byte[] buf = read_size_and_inflate();

    final EInputStream ois = new EInputStream(buf, flags);
    return ois.read_any();
  }
Пример #3
0
 public long read_long(final boolean unsigned) throws IOException {
   final byte[] b = read_integer_byte_array();
   return EInputStream.byte_array_to_long(b, unsigned);
 }