hessianinput.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,701 行 · 第 1/3 页
JAVA
1,701 行
ByteArrayOutputStream bos = new ByteArrayOutputStream(); while ((data = parseByte()) >= 0) bos.write(data); return bos.toByteArray(); } case 'V': { String type = readType(); int length = readLength(); return _serializerFactory.readList(this, length, type); } case 'M': { String type = readType(); return _serializerFactory.readMap(this, type); } case 'R': { int ref = parseInt(); return _refs.get(ref); } case 'r': { String type = readType(); String url = readString(); return resolveRemote(type, url); } default: throw error("unknown code for readObject at " + codeName(tag)); } } /** * Reads a remote object. */ public Object readRemote() throws IOException { String type = readType(); String url = readString(); return resolveRemote(type, url); } /** * Reads a reference. */ public Object readRef() throws IOException { return _refs.get(parseInt()); } /** * Reads the start of a list. */ public int readListStart() throws IOException { return read(); } /** * Reads the start of a list. */ public int readMapStart() throws IOException { return read(); } /** * Returns true if this is the end of a list or a map. */ public boolean isEnd() throws IOException { int code = read(); _peek = code; return (code < 0 || code == 'z'); } /** * Reads the end byte. */ public void readEnd() throws IOException { int code = read(); if (code != 'z') throw error("unknown code at " + codeName(code)); } /** * Reads the end byte. */ 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. */ public void readListEnd() throws IOException { int code = read(); if (code != 'z') throw error("expected end of list ('z') at " + codeName(code)); } /** * Adds a list/map reference. */ public int addRef(Object ref) { if (_refs == null) _refs = new ArrayList(); _refs.add(ref); return _refs.size() - 1; } /** * Adds a list/map reference. */ public void setRef(int i, Object ref) { _refs.set(i, ref); } /** * Resets the references for streaming. */ public void resetReferences() { if (_refs != null) _refs.clear(); } /** * 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); } /** * Parses a type from the stream. * * <pre> * t b16 b8 * </pre> */ 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(); } /** * Parses the length for an array * * <pre> * l b32 b24 b16 b8 * </pre> */ public int readLength() throws IOException { int code = read(); if (code != 'l') { _peek = code; return -1; } return parseInt(); } /** * Parses a 32-bit integer value from the stream. * * <pre> * b32 b24 b16 b8 * </pre> */ private int parseInt() throws IOException { int b32 = read(); int b24 = read(); int b16 = read(); int b8 = read(); return (b32 << 24) + (b24 << 16) + (b16 << 8) + b8; } /** * Parses a 64-bit long value from the stream. * * <pre> * b64 b56 b48 b40 b32 b24 b16 b8 * </pre> */ private long parseLong() throws IOException { long b64 = read(); long b56 = read(); long b48 = read(); long b40 = read(); long b32 = read(); long b24 = read(); long b16 = read(); long b8 = read(); return ((b64 << 56) + (b56 << 48) + (b48 << 40) + (b40 << 32) + (b32 << 24) + (b24 << 16) + (b16 << 8) + b8); } /** * Parses a 64-bit double value from the stream. * * <pre> * b64 b56 b48 b40 b32 b24 b16 b8 * </pre> */ private double parseDouble() throws IOException { long b64 = read(); long b56 = read(); long b48 = read(); long b40 = read(); long b32 = read(); long b24 = read(); long b16 = read(); long b8 = read(); long bits = ((b64 << 56) + (b56 << 48) + (b48 << 40) + (b40 << 32) + (b32 << 24) + (b24 << 16) + (b16 << 8) + b8); return Double.longBitsToDouble(bits); } org.w3c.dom.Node parseXML() throws IOException { throw new UnsupportedOperationException(); } /** * 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(); } /** * 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)); } /** * Reads a byte from the underlying stream. */ private int parseByte() throws IOException { while (_chunkLength <= 0) { if (_isLastChunk) { return -1; } int code = read(); switch (code) { case 'b': _isLastChunk = false; _chunkLength = (read() << 8) + read(); break; case 'B': _isLastChunk = true; _chunkLength = (read() << 8) + read(); break; default: throw expect("byte[]", code); } } _chunkLength--; return read(); } /** * Reads bytes based on an input stream. */ public InputStream readInputStream() throws IOException { int tag = read(); switch (tag) { case 'N': return null; case 'B': case 'b': _isLastChunk = tag == 'B'; _chunkLength = (read() << 8) + read(); break; default: throw expect("inputStream", tag); } return new InputStream() { boolean _isClosed = false; public int read() throws IOException { if (_isClosed || _is == null) return -1; int ch = parseByte(); if (ch < 0) _isClosed = true; return ch; } 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; } public void close() throws IOException { while (read() >= 0) { } _isClosed = true; } }; } /** * Reads bytes from the underlying stream. */ int read(byte []buffer, int offset, int length) throws IOException { int readLength = 0; while (length > 0) { while (_chunkLength <= 0) { if (_isLastChunk) return readLength == 0 ? -1 : readLength; int code = read(); switch (code) { case 'b': _isLastChunk = false; _chunkLength = (read() << 8) + read(); break; case 'B': _isLastChunk = true; _chunkLength = (read() << 8) + read(); break; default: throw expect("byte[]", code); } } int sublen = _chunkLength; if (length < sublen) sublen = length; sublen = _is.read(buffer, offset, sublen); offset += sublen; readLength += sublen; length -= sublen; _chunkLength -= sublen; } return readLength; } final int read() throws IOException { if (_peek >= 0) { int value = _peek; _peek = -1; return value; } int ch = _is.read(); return ch; } public void close() { _is = null; } public Reader getReader() { return null; } protected IOException expect(String expect, int ch) { return error("expected " + expect + " at " + codeName(ch)); } protected String codeName(int ch) { if (ch < 0) return "end of file"; else return "0x" + Integer.toHexString(ch & 0xff) + " (" + (char) + ch + ")"; } protected IOException error(String message) { if (_method != null) return new HessianProtocolException(_method + ": " + message); else return new HessianProtocolException(message); } static { try { _detailMessageField = Throwable.class.getDeclaredField("detailMessage"); _detailMessageField.setAccessible(true); } catch (Throwable e) { } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?