public AbstractHessianInput open(InputStream is) throws IOException { int code = is.read(); int major = is.read(); int minor = is.read(); switch (code) { case 'c': case 'C': case 'r': case 'R': if (major >= 2) { AbstractHessianInput in = new Hessian2Input(is); in.setSerializerFactory(_serializerFactory); return in; } else { AbstractHessianInput in = new HessianInput(is); in.setSerializerFactory(_serializerFactory); return in; } default: throw new IOException((char) code + " is an unknown Hessian message code."); } } }
public Object readObject() throws IOException { int tag = read(); return Integer.valueOf(parseInt()); return Long.valueOf(parseLong()); return Double.valueOf(parseDouble()); return new Date(parseLong()); _chunkLength = (read() << 8) + read(); return parseXML(); case 'S': { _isLastChunk = tag == 'S'; _chunkLength = (read() << 8) + read(); while ((data = parseChar()) >= 0) _sbuf.append((char) data); case 'B': { _isLastChunk = tag == 'B'; _chunkLength = (read() << 8) + read(); while ((data = parseByte()) >= 0) bos.write(data);
/** * 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 an integer * <p> * <pre> * I b32 b24 b16 b8 * </pre> */ @Override public int readInt() throws IOException { int tag = read(); switch (tag) { case 'T': return 1; case 'F': return 0; case 'I': return parseInt(); case 'L': return (int) parseLong(); case 'D': return (int) parseDouble(); default: throw expect("int", tag); } }
/** * Reads a byte array * <p> * <pre> * B b16 b8 data value * </pre> */ @Override public byte[] readBytes() throws IOException { int tag = read(); switch (tag) { case 'N': return null; case 'B': case 'b': _isLastChunk = tag == 'B'; _chunkLength = (read() << 8) + read(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int data; while ((data = parseByte()) >= 0) bos.write(data); return bos.toByteArray(); default: throw expect("bytes", tag); } }
/** * 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 call * <p> * <p>A successful completion will have a single value: * <p> * <pre> * m b16 b8 method * </pre> */ @Override public String readMethod() throws IOException { int tag = read(); if (tag != 'm') throw error("expected hessian method ('m') at " + codeName(tag)); int d1 = read(); int d2 = read(); _isLastChunk = true; _chunkLength = d1 * 256 + d2; _sbuf.setLength(0); int ch; while ((ch = parseChar()) >= 0) _sbuf.append((char) ch); _method = _sbuf.toString(); return _method; }
/** * 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 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 an XML node. * <p> * <pre> * S b16 b8 string value * </pre> */ @Override public org.w3c.dom.Node readNode() throws IOException { int tag = read(); switch (tag) { case 'N': return null; case 'S': case 's': case 'X': case 'x': _isLastChunk = tag == 'S' || tag == 'X'; _chunkLength = (read() << 8) + read(); throw error("Can't handle string in this context"); default: throw expect("string", tag); } }
/** * Reads a character from the underlying stream. */ private int parseChar() throws IOException { while (_chunkLength <= 0) { if (_isLastChunk) return -1; int code = read(); switch (code) { case 's': case 'x': _isLastChunk = false; _chunkLength = (read() << 8) + read(); break; case 'S': case 'X': _isLastChunk = true; _chunkLength = (read() << 8) + read(); break; default: throw expect("string", code); } } _chunkLength--; return parseUTF8Char(); }
/** * Creates a new Hessian input stream, initialized with an * underlying input stream. * * @param is the underlying input stream. */ public HessianInput(InputStream is) { init(is); }
/** * Resolves a remote object. */ public Object resolveRemote(String type, String url) throws IOException { HessianRemoteResolver resolver = getRemoteResolver(); if (resolver != null) return resolver.lookup(type, url); else return new HessianRemote(type, url); }
/** * Reads a double * <p> * <pre> * D b64 b56 b48 b40 b32 b24 b16 b8 * </pre> */ @Override public double readDouble() throws IOException { int tag = read(); switch (tag) { case 'T': return 1; case 'F': return 0; case 'I': return parseInt(); case 'L': return (double) parseLong(); case 'D': return parseDouble(); default: throw expect("long", tag); } }
/** * Reads a byte array * <p> * <pre> * B b16 b8 data value * </pre> */ @Override public byte[] readBytes() throws IOException { int tag = read(); switch (tag) { case 'N': return null; case 'B': case 'b': _isLastChunk = tag == 'B'; _chunkLength = (read() << 8) + read(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int data; while ((data = parseByte()) >= 0) bos.write(data); return bos.toByteArray(); default: throw expect("bytes", tag); } }