public byte[] read_size_and_inflate() throws IOException { final int size = read4BE(); final byte[] buf = new byte[size]; final java.util.zip.Inflater inflater = new java.util.zip.Inflater(); final java.util.zip.InflaterInputStream is = new java.util.zip.InflaterInputStream(this, inflater); try { int pos = 0; while (pos < size) { // Inflate fully final int dsize = is.read(buf, pos, size - pos); if (dsize == 0) break; pos += dsize; } if (pos < size) { throw new IOException("Decompression gave " + pos + " bytes, not " + size); } // Back up if the inflater read ahead: int read_ahead = inflater.getRemaining(); setPos(getPos() - read_ahead); } finally { is.close(); } return buf; }
public EInteger read_tagged_integer() throws IOException { int tag = read1skip_version(); switch (tag) { case EExternal.smallIntTag: return new ESmall(read1()); case EExternal.intTag: return new ESmall(read4BE()); default: setPos(getPos() - 1); return ERT.box(new BigInteger(read_integer_byte_array())); } // switch }
/** * Read an arbitrary Erlang term from the stream. * * @return the Erlang term. * @exception IOException if the stream does not contain a known Erlang type at the next position. */ public EObject read_any() throws IOException { // calls one of the above functions, depending on o final int tag = peek1skip_version(); switch (tag) { case EExternal.smallIntTag: case EExternal.intTag: case EExternal.smallBigTag: case EExternal.largeBigTag: return EInteger.read(this); case EExternal.atomCacheRef: case EExternal.atomTag: case EExternal.smallAtomTag: return EAtom.read(this); case EExternal.floatTag: case EExternal.newFloatTag: return EDouble.read(this); case EExternal.refTag: case EExternal.newRefTag: return ERef.read(this); case EExternal.portTag: return EPort.read(this); case EExternal.pidTag: return EPID.read(this); case EExternal.stringTag: return EString.read(this); case EExternal.listTag: case EExternal.nilTag: if ((flags & DECODE_INT_LISTS_AS_STRINGS) != 0) { final int savePos = getPos(); try { return EString.read(this); } catch (final IOException e) { } setPos(savePos); } return EList.read(this); case EExternal.smallTupleTag: case EExternal.largeTupleTag: return ETuple.read(this); case EExternal.binTag: return EBinary.read(this); case EExternal.bitBinTag: return EBitString.read(this); case EExternal.compressedTag: return read_compressed(); case EExternal.newFunTag: case EExternal.funTag: return EFun.read(this); case EExternal.externalFunTag: return read_external_fun(); default: throw new IOException("Unknown data type: " + tag + " at position " + getPos()); } }