protected IOException expect(String expect, int ch) throws IOException { if (ch < 0) return error("expected " + expect + " at end of file"); else { _offset--; try { Object obj = readObject(); if (obj != null) { return error("expected " + expect + " at 0x" + Integer.toHexString(ch & 0xff) + " " + obj.getClass().getName() + " (" + obj + ")"); } else return error("expected " + expect + " at 0x" + Integer.toHexString(ch & 0xff) + " null"); } catch (IOException e) { log.log(Level.FINE, e.toString(), e); return error("expected " + expect + " at 0x" + Integer.toHexString(ch & 0xff)); } } }
/** * Reads the end byte. */ @Override public void readListEnd() throws IOException { int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read(); if (code != 'Z') throw error("expected end of list ('Z') at '" + codeName(code) + "'"); }
/** * Reads the end byte. */ @Override public void readMapEnd() throws IOException { int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read(); if (code != 'Z') throw error("expected end of map ('Z') at '" + codeName(code) + "'"); }
/** * Completes reading the envelope * <p> * <p>A successful completion will have a single value: * <p> * <pre> * Z * </pre> */ public void completeEnvelope() throws IOException { int tag = read(); if (tag != 'Z') error("expected end of envelope at " + codeName(tag)); }
/** * Starts reading the call * <p> * <pre> * c major minor * </pre> */ @Override public int readCall() throws IOException { int tag = read(); if (tag != 'C') throw error("expected hessian call ('C') at " + codeName(tag)); return 0; }
/** * 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 message * <p> * <p>A successful completion will have a single value: * <p> * <pre> * z * </pre> */ public void completeMessage() throws IOException { int tag = read(); if (tag != 'Z') error("expected end of message at " + codeName(tag)); }
/** * 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') return readObject(expectedClass); else if (tag == 'F') { HashMap map = (HashMap) readObject(HashMap.class); throw prepareFault(map); } else { StringBuilder sb = new StringBuilder(); sb.append((char) tag); try { int ch; while ((ch = read()) >= 0) { sb.append((char) ch); } } catch (IOException e) { log.log(Level.FINE, e.toString(), e); } throw error("expected hessian reply at " + codeName(tag) + "\n" + sb); } }
/** * Starts reading the message * <p> * <pre> * p major minor * </pre> */ public int startMessage() throws IOException { int tag = read(); if (tag == 'p') _isStreaming = false; else if (tag == 'P') _isStreaming = true; else throw error("expected Hessian message ('p') at " + codeName(tag)); int major = read(); int minor = read(); return (major << 16) + minor; }
/** * Starts reading the envelope * <p> * <pre> * E major minor * </pre> */ public int readEnvelope() throws IOException { int tag = read(); int version = 0; if (tag == 'H') { int major = read(); int minor = read(); version = (major << 16) + minor; tag = read(); } if (tag != 'E') throw error("expected hessian Envelope ('E') at " + codeName(tag)); return version; }
/** * Parses a single UTF8 character. */ private int parseUTF8Char() throws IOException { int ch = _offset < _length ? (_buffer[_offset++] & 0xff) : 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)); }
/** * Reads the end byte. */ @Override public void readListEnd() throws IOException { int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read(); if (code != 'Z') throw error("expected end of list ('Z') at '" + codeName(code) + "'"); }
/** * Reads the end byte. */ public void readMapEnd() throws IOException { int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read(); if (code != 'Z') throw error("expected end of map ('Z') at '" + codeName(code) + "'"); }
/** * Reads the end byte. */ public void readListEnd() throws IOException { int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read(); if (code != 'Z') throw error("expected end of list ('Z') at '" + codeName(code) + "'"); }
/** * Reads the end byte. */ public void readMapEnd() throws IOException { int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read(); if (code != 'Z') throw error("expected end of map ('Z') at '" + codeName(code) + "'"); }
/** * Reads the end byte. */ public void readListEnd() throws IOException { int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read(); if (code != 'Z') throw error("expected end of list ('Z') at '" + codeName(code) + "'"); }
/** * Reads the end byte. */ public void readListEnd() throws IOException { int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read(); if (code != 'Z') throw error("expected end of list ('Z') at '" + codeName(code) + "'"); }
/** * Reads the end byte. */ @Override public void readMapEnd() throws IOException { int code = _offset < _length ? (_buffer[_offset++] & 0xff) : read(); if (code != 'Z') throw error("expected end of map ('Z') at '" + codeName(code) + "'"); }