/** * Returns true if this is the end of a list or a map. */ @Override public boolean isEnd() throws IOException { int code = read(); _peek = code; return (code < 0 || code == 'z'); }
/** * Reads a fault. */ private HashMap readFault() throws IOException { HashMap map = new HashMap(); int code = read(); for (; code > 0 && code != 'z'; code = read()) { _peek = code; Object key = readObject(); Object value = readObject(); if (key != null && value != null) map.put(key, value); } if (code != 'z') throw expect("fault", code); return map; }
/** * Reads the start of a list. */ @Override public int readListStart() throws IOException { return read(); }
/** * Reads a reply as an object. * If the reply has a fault, throws the exception. */ @Override public Object readReply(Class expectedClass) throws Throwable { int tag = read(); if (tag != 'r') error("expected hessian reply at " + codeName(tag)); int major = read(); int minor = read(); tag = read(); if (tag == 'f') throw prepareFault(); else { _peek = tag; Object value = readObject(expectedClass); completeValueReply(); return value; } }
/** * Reads the start of a list. */ @Override public int readMapStart() throws IOException { return read(); }
@Override public int read(byte[] buffer, int offset, int length) throws IOException { if (_isClosed || _is == null) return -1; int len = HessianInput.this.read(buffer, offset, length); if (len < 0) _isClosed = true; return len; }
/** * Parses a single UTF8 character. */ private int parseUTF8Char() throws IOException { int ch = read(); if (ch < 0x80) return ch; else if ((ch & 0xe0) == 0xc0) { int ch1 = read(); int v = ((ch & 0x1f) << 6) + (ch1 & 0x3f); return v; } else if ((ch & 0xf0) == 0xe0) { int ch1 = read(); int ch2 = read(); int v = ((ch & 0x0f) << 12) + ((ch1 & 0x3f) << 6) + (ch2 & 0x3f); return v; } else throw error("bad utf-8 encoding at " + codeName(ch)); }
/** * Parses a type from the stream. * <p> * <pre> * t b16 b8 * </pre> */ @Override public String readType() throws IOException { int code = read(); if (code != 't') { _peek = code; return ""; } _isLastChunk = true; _chunkLength = (read() << 8) + read(); _sbuf.setLength(0); int ch; while ((ch = parseChar()) >= 0) _sbuf.append((char) ch); return _sbuf.toString(); }
/** * Starts reading the reply * <p> * <p>A successful completion will have a single value: * <p> * <pre> * r * </pre> */ @Override public void startReply() throws Throwable { int tag = read(); if (tag != 'r') error("expected hessian reply at " + codeName(tag)); int major = read(); int minor = read(); tag = read(); if (tag == 'f') throw prepareFault(); else _peek = tag; }
/** * Reads a null * <p> * <pre> * N * </pre> */ @Override public void readNull() throws IOException { int tag = read(); switch (tag) { case 'N': return; default: throw expect("null", tag); } }
/** * Parses the length for an array * <p> * <pre> * l b32 b24 b16 b8 * </pre> */ @Override public int readLength() throws IOException { int code = read(); if (code != 'l') { _peek = code; return -1; } return parseInt(); }
/** * Reads the end byte. */ @Override public void readEnd() throws IOException { int code = read(); if (code != 'z') throw error("unknown code at " + codeName(code)); }
/** * Reads the end byte. */ @Override public void readMapEnd() throws IOException { int code = read(); if (code != 'z') throw error("expected end of map ('z') at " + codeName(code)); }
/** * Reads the end byte. */ @Override public void readListEnd() throws IOException { int code = read(); if (code != 'z') throw error("expected end of list ('z') at " + codeName(code)); }
/** * Completes reading the call * <p> * <p>A successful completion will have a single value: * <p> * <pre> * z * </pre> */ public void completeValueReply() throws IOException { int tag = read(); if (tag != 'z') error("expected end of reply at " + codeName(tag)); }
/** * Completes reading the call * <p> * <p>A successful completion will have a single value: * <p> * <pre> * z * </pre> */ @Override public void completeReply() throws IOException { int tag = read(); if (tag != 'z') error("expected end of reply at " + codeName(tag)); }
/** * Completes reading the call * <p> * <p>A successful completion will have a single value: * <p> * <pre> * z * </pre> */ @Override public void completeCall() throws IOException { int tag = read(); if (tag == 'z') { } else throw error("expected end of call ('z') at " + codeName(tag) + ". Check method arguments and ensure method overloading is enabled if necessary"); }