private BigCouchUpdateSequence(final String encodedVector, final String packedSeqs) { this.since = encodedVector; final byte[] bytes = new Base64(true).decode(packedSeqs); final OtpInputStream stream = new OtpInputStream(bytes); try { final OtpErlangList list = (OtpErlangList) stream.read_any(); for (int i = 0, arity = list.arity(); i < arity; i++) { final OtpErlangTuple tuple = (OtpErlangTuple) list.elementAt(i); final OtpErlangObject node = tuple.elementAt(0); final OtpErlangObject range = tuple.elementAt(1); final OtpErlangObject seq_obj = tuple.elementAt(2); final OtpErlangLong node_seq; if (seq_obj instanceof OtpErlangLong) { node_seq = (OtpErlangLong) seq_obj; } else if (seq_obj instanceof OtpErlangTuple) { node_seq = (OtpErlangLong) ((OtpErlangTuple)seq_obj).elementAt(0); } else { throw new IllegalArgumentException("could not decode seq"); } vector.put(node + "-" + range, node_seq.longValue()); } } catch (final OtpErlangDecodeException e) { throw new IllegalArgumentException(encodedVector + " not valid."); } }
public OtpErlangFun read_fun() throws OtpErlangDecodeException { final int tag = read1skip_version(); if (tag == OtpExternal.funTag) { final int nFreeVars = read4BE(); final OtpErlangPid pid = read_pid(); final String module = read_atom(); final long index = read_long(); final long uniq = read_long(); final OtpErlangObject[] freeVars = new OtpErlangObject[nFreeVars]; for (int i = 0; i < nFreeVars; ++i) { freeVars[i] = read_any(); read4BE(); final int arity = read1(); final byte[] md5 = new byte[16]; readN(md5); final int index = read4BE(); final int nFreeVars = read4BE(); final String module = read_atom(); final long oldIndex = read_long(); final long uniq = read_long(); final OtpErlangPid pid = read_pid(); final OtpErlangObject[] freeVars = new OtpErlangObject[nFreeVars]; for (int i = 0; i < nFreeVars; ++i) { freeVars[i] = read_any();
/** * Create a binary from a stream containing a binary encoded in Erlang * external format. * * @param buf * the stream containing the encoded binary. * * @exception OtpErlangDecodeException * if the buffer does not contain a valid external * representation of an Erlang binary. */ public OtpErlangBinary(final OtpInputStream buf) throws OtpErlangDecodeException { super(new byte[0]); bin = buf.read_binary(); pad_bits = 0; }
/** * Create a tuple from a stream containing an tuple encoded in Erlang * external format. * * @param buf * the stream containing the encoded tuple. * * @exception OtpErlangDecodeException * if the buffer does not contain a valid external * representation of an Erlang tuple. */ public OtpErlangTuple(final OtpInputStream buf) throws OtpErlangDecodeException { final int arity = buf.read_tuple_head(); if (arity > 0) { elems = new OtpErlangObject[arity]; for (int i = 0; i < arity; i++) { elems[i] = buf.read_any(); } } else { elems = NO_ELEMENTS; } }
/** * Create a list from a stream containing an list encoded in Erlang external * format. * * @param buf * the stream containing the encoded list. * * @exception OtpErlangDecodeException * if the buffer does not contain a valid external * representation of an Erlang list. */ public OtpErlangList(final OtpInputStream buf) throws OtpErlangDecodeException { final int arity = buf.read_list_head(); if (arity > 0) { elems = new OtpErlangObject[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() == OtpExternal.nilTag) { buf.read_nil(); } else { lastTail = buf.read_any(); } } else { elems = NO_ELEMENTS; } }
int firstByte = ttbInputStream.read1skip_version(); ttbInputStream.reset(); ttbMsgArity = ttbInputStream.read_tuple_head(); try atom = ttbInputStream.read_atom(); String errMsg = new String(ttbInputStream.read_binary(), StandardCharsets.UTF_8); int errCode = ttbInputStream.read_int(); return new RiakResponseException(errCode, errMsg);
ibuf = new OtpInputStream(lbuf, flags); len = ibuf.read4BE(); ibuf.close(); ibuf = new OtpInputStream(tmpbuf, flags); if (ibuf.read1() != passThrough) { break receive_loop; tmp = ibuf.read_any(); if (!(tmp instanceof OtpErlangTuple)) { break receive_loop; ibuf.mark(0); traceobj = ibuf.read_any(); System.out.println(" (null)"); ibuf.reset(); ibuf.mark(0); traceobj = ibuf.read_any(); System.out.println(" (null)"); ibuf.reset();
/** * Read an Erlang PID from the stream. * * @return the value of the PID. * * @exception OtpErlangDecodeException * if the next term in the stream is not an Erlang PID. */ public OtpErlangPid read_pid() throws OtpErlangDecodeException { String node; int id; int serial; int creation; int tag; tag = read1skip_version(); if (tag != OtpExternal.pidTag) { throw new OtpErlangDecodeException( "Wrong tag encountered, expected " + OtpExternal.pidTag + ", got " + tag); } node = read_atom(); id = read4BE() & 0x7fff; // 15 bits serial = read4BE() & 0x1fff; // 13 bits creation = read1() & 0x03; // 2 bits return new OtpErlangPid(node, id, serial, creation); }
final byte[] buf = read2BytePackage(); @SuppressWarnings("resource") final OtpInputStream ibuf = new OtpInputStream(buf, 0); peer.ntype = ibuf.read1(); if (peer.ntype != AbstractNode.NTYPE_R6) { throw new IOException("Unexpected peer type"); peer.distLow = peer.distHigh = ibuf.read2BE(); peer.flags = ibuf.read4BE(); challenge = ibuf.read4BE(); final byte[] tmpname = new byte[buf.length - 11]; ibuf.readN(tmpname); final String hisname = OtpErlangString.newString(tmpname); if (!hisname.equals(peer.node)) {
byte[] strbuf; int[] intbuf; tag = read1skip_version(); switch (tag) { case OtpExternal.stringTag: len = read2BE(); strbuf = new byte[len]; this.readN(strbuf); return OtpErlangString.newString(strbuf); case OtpExternal.nilTag: return ""; case OtpExternal.listTag: // List when unicode + len = read4BE(); intbuf = new int[len]; for (int i = 0; i < len; i++) { intbuf[i] = read_int(); if (!OtpErlangString.isValidCodePoint(intbuf[i])) { throw new OtpErlangDecodeException("Invalid CodePoint: " read_nil(); return new String(intbuf, 0, intbuf.length); default:
final int tag = read1skip_version(); final int size = read4BE(); final byte[] abuf = new byte[size]; final java.util.zip.InflaterInputStream is = new java.util.zip.InflaterInputStream( final OtpInputStream ois = new OtpInputStream(abuf, flags); return ois.read_any();
private static ArrayList<RiakTsPB.TsColumnDescription> parseColumnDescriptions(OtpInputStream is) throws OtpErlangDecodeException final int colNameCount = is.read_list_head(); final String[] columnNames = new String[colNameCount]; for (int colNameIdx = 0; colNameIdx < colNameCount; colNameIdx++) final String colName = new String(is.read_binary(), StandardCharsets.UTF_8); columnNames[colNameIdx] = colName; is.read_nil(); final int colTypeCount = is.read_list_head(); assert (colNameCount == colTypeCount); final String[] columnTypes = new String[colTypeCount]; for (int colTypeIdx = 0; colTypeIdx < colTypeCount; colTypeIdx++) final String colType = is.read_atom(); columnTypes[colTypeIdx] = colType; is.read_nil();
private static QueryResult decodeTsResponse(byte[] response) throws OtpErlangDecodeException, InvalidTermToBinaryException { final OtpInputStream is = new OtpInputStream(response); final int firstByte = is.read1skip_version(); is.reset(); if (firstByte != OtpExternal.smallTupleTag && firstByte != OtpExternal.largeTupleTag) { return parseAtomResult(is); } return parseTupleResult(is); }
protected void recvStatus() throws IOException { try { final byte[] buf = read2BytePackage(); @SuppressWarnings("resource") final OtpInputStream ibuf = new OtpInputStream(buf, 0); final int tag = ibuf.read1(); if (tag != ChallengeStatus) { throw new IOException("Handshake protocol error"); } final byte[] tmpbuf = new byte[buf.length - 1]; ibuf.readN(tmpbuf); final String status = OtpErlangString.newString(tmpbuf); if (status.compareTo("ok") != 0) { throw new IOException("Peer replied with status '" + status + "' instead of 'ok'"); } } catch (final OtpErlangDecodeException e) { throw new IOException("Handshake failed - not enough data"); } if (traceLevel >= handshakeThreshold) { System.out.println("<- " + "HANDSHAKE recvStatus (ok)" + " local=" + localNode); } }
byte[] bin; tag = read1skip_version(); len = read4BE(); bin = new byte[len]; final int tail_bits = read1(); if (tail_bits < 0 || 7 < tail_bits) { throw new OtpErlangDecodeException( "Length 0 on bitstr with tail bit count: " + tail_bits); this.readN(bin);
final OtpInputStream ibuf = new OtpInputStream(tmpbuf, 0); final int response = ibuf.read1(); if (response == port4resp) { final int result = ibuf.read1(); if (result == 0) { port = ibuf.read2BE(); node.ntype = ibuf.read1(); node.proto = ibuf.read1(); node.distHigh = ibuf.read2BE(); node.distLow = ibuf.read2BE();
/** * Read binary data in the Erlang external format, and produce a * corresponding Erlang data type object. This method is normally used when * Erlang terms are received in messages, however it can also be used for * reading terms from disk. * * @param buf * an input stream containing one or more encoded Erlang terms. * * @return an object representing one of the Erlang data types. * * @exception OtpErlangDecodeException * if the stream does not contain a valid representation of * an Erlang term. */ public static OtpErlangObject decode(final OtpInputStream buf) throws OtpErlangDecodeException { return buf.read_any(); }
public OtpErlangExternalFun read_external_fun() throws OtpErlangDecodeException { final int tag = read1skip_version(); if (tag != OtpExternal.externalFunTag) { throw new OtpErlangDecodeException( "Wrong tag encountered, expected external fun, got " + tag); } final String module = read_atom(); final String function = read_atom(); final int arity = (int) read_long(); return new OtpErlangExternalFun(module, function, arity); }
/** * Read an Erlang binary from the stream. * * @return a byte array containing the value of the binary. * * @exception OtpErlangDecodeException * if the next term in the stream is not a binary. */ public byte[] read_binary() throws OtpErlangDecodeException { int tag; int len; byte[] bin; tag = read1skip_version(); if (tag != OtpExternal.binTag) { throw new OtpErlangDecodeException( "Wrong tag encountered, expected " + OtpExternal.binTag + ", got " + tag); } len = read4BE(); bin = new byte[len]; this.readN(bin); return bin; }