hessian2output.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,662 行 · 第 1/3 页
JAVA
1,662 行
* <code>writeMapBegin</code> followed by the map contents and then * call <code>writeMapEnd</code>. * * <code><pre> * Mt b16 b8 (<key> <value>)z * </pre></code> */ public void writeMapBegin(String type) throws IOException { if (SIZE < _offset + 32) flush(); _buffer[_offset++] = 'M'; writeType(type); } /** * Writes the tail of the map to the stream. */ public void writeMapEnd() throws IOException { if (SIZE < _offset + 32) flush(); _buffer[_offset++] = (byte) 'z'; } /** * Writes the object definition * * <code><pre> * O t b16 b8 <string>* * </pre></code> */ public int writeObjectBegin(String type) throws IOException { if (_classRefs == null) _classRefs = new HashMap(); Integer refV = (Integer) _classRefs.get(type); if (refV != null) { int ref = refV.intValue(); if (SIZE < _offset + 32) flush(); _buffer[_offset++] = (byte) 'o'; writeInt(ref); return ref; } else { int ref = _classRefs.size(); _classRefs.put(type, Integer.valueOf(ref)); if (SIZE < _offset + 32) flush(); _buffer[_offset++] = (byte) 'O'; writeString(type); return -1; } } /** * Writes the tail of the class definition to the stream. */ public void writeClassFieldLength(int len) throws IOException { writeInt(len); } /** * Writes the tail of the object definition to the stream. */ public void writeObjectEnd() throws IOException { } /** * Writes a remote object reference to the stream. The type is the * type of the remote interface. * * <code><pre> * 'r' 't' b16 b8 type url * </pre></code> */ public void writeRemote(String type, String url) throws IOException { if (SIZE < _offset + 32) flush(); _buffer[_offset++] = (byte) 'r'; writeType(type); if (SIZE < _offset + 32) flush(); _buffer[_offset++] = (byte) 'S'; printLenString(url); } private void writeType(String type) throws IOException { if (type == null) return; int len = type.length(); if (len == 0) return; if (_typeRefs == null) _typeRefs = new HashMap(); Integer typeRefV = (Integer) _typeRefs.get(type); if (typeRefV != null) { int typeRef = typeRefV.intValue(); flushIfFull(); _buffer[_offset++] = (byte) TYPE_REF; writeInt(typeRef); } else { _typeRefs.put(type, Integer.valueOf(_typeRefs.size())); if (SIZE < _offset + 32) flush(); _buffer[_offset++] = (byte) 't'; printLenString(type); } } /** * Writes a boolean value to the stream. The boolean will be written * with the following syntax: * * <code><pre> * T * F * </pre></code> * * @param value the boolean value to write. */ public void writeBoolean(boolean value) throws IOException { if (SIZE < _offset + 16) flush(); if (value) _buffer[_offset++] = (byte) 'T'; else _buffer[_offset++] = (byte) 'F'; } /** * Writes an integer value to the stream. The integer will be written * with the following syntax: * * <code><pre> * I b32 b24 b16 b8 * </pre></code> * * @param value the integer value to write. */ public void writeInt(int value) throws IOException { int offset = _offset; byte []buffer = _buffer; if (SIZE <= offset + 16) { flush(); offset = _offset; } if (INT_DIRECT_MIN <= value && value <= INT_DIRECT_MAX) buffer[offset++] = (byte) (value + INT_ZERO); else if (INT_BYTE_MIN <= value && value <= INT_BYTE_MAX) { buffer[offset++] = (byte) (INT_BYTE_ZERO + (value >> 8)); buffer[offset++] = (byte) (value); } else if (INT_SHORT_MIN <= value && value <= INT_SHORT_MAX) { buffer[offset++] = (byte) (INT_SHORT_ZERO + (value >> 16)); buffer[offset++] = (byte) (value >> 8); buffer[offset++] = (byte) (value); } else { buffer[offset++] = (byte) ('I'); buffer[offset++] = (byte) (value >> 24); buffer[offset++] = (byte) (value >> 16); buffer[offset++] = (byte) (value >> 8); buffer[offset++] = (byte) (value); } _offset = offset; } /** * Writes a long value to the stream. The long will be written * with the following syntax: * * <code><pre> * L b64 b56 b48 b40 b32 b24 b16 b8 * </pre></code> * * @param value the long value to write. */ public void writeLong(long value) throws IOException { int offset = _offset; byte []buffer = _buffer; if (SIZE <= offset + 16) { flush(); offset = _offset; } if (LONG_DIRECT_MIN <= value && value <= LONG_DIRECT_MAX) { buffer[offset++] = (byte) (value + LONG_ZERO); } else if (LONG_BYTE_MIN <= value && value <= LONG_BYTE_MAX) { buffer[offset++] = (byte) (LONG_BYTE_ZERO + (value >> 8)); buffer[offset++] = (byte) (value); } else if (LONG_SHORT_MIN <= value && value <= LONG_SHORT_MAX) { buffer[offset++] = (byte) (LONG_SHORT_ZERO + (value >> 16)); buffer[offset++] = (byte) (value >> 8); buffer[offset++] = (byte) (value); } else if (-0x80000000L <= value && value <= 0x7fffffffL) { buffer[offset + 0] = (byte) LONG_INT; buffer[offset + 1] = (byte) (value >> 24); buffer[offset + 2] = (byte) (value >> 16); buffer[offset + 3] = (byte) (value >> 8); buffer[offset + 4] = (byte) (value); offset += 5; } else { buffer[offset + 0] = (byte) 'L'; buffer[offset + 1] = (byte) (value >> 56); buffer[offset + 2] = (byte) (value >> 48); buffer[offset + 3] = (byte) (value >> 40); buffer[offset + 4] = (byte) (value >> 32); buffer[offset + 5] = (byte) (value >> 24); buffer[offset + 6] = (byte) (value >> 16); buffer[offset + 7] = (byte) (value >> 8); buffer[offset + 8] = (byte) (value); offset += 9; } _offset = offset; } /** * Writes a double value to the stream. The double will be written * with the following syntax: * * <code><pre> * D b64 b56 b48 b40 b32 b24 b16 b8 * </pre></code> * * @param value the double value to write. */ public void writeDouble(double value) throws IOException { int offset = _offset; byte []buffer = _buffer; if (SIZE <= offset + 16) { flush(); offset = _offset; } int intValue = (int) value; if (intValue == value) { if (intValue == 0) { buffer[offset++] = (byte) DOUBLE_ZERO; _offset = offset; return; } else if (intValue == 1) { buffer[offset++] = (byte) DOUBLE_ONE; _offset = offset; return; } else if (-0x80 <= intValue && intValue < 0x80) { buffer[offset++] = (byte) DOUBLE_BYTE; buffer[offset++] = (byte) intValue; _offset = offset; return; } else if (-0x8000 <= intValue && intValue < 0x8000) { buffer[offset + 0] = (byte) DOUBLE_SHORT; buffer[offset + 1] = (byte) (intValue >> 8); buffer[offset + 2] = (byte) intValue; _offset = offset + 3; return; } } float f = (float) value; if (f == value) { int bits = Float.floatToIntBits(f); buffer[offset + 0] = (byte) (DOUBLE_FLOAT); buffer[offset + 1] = (byte) (bits >> 24); buffer[offset + 2] = (byte) (bits >> 16); buffer[offset + 3] = (byte) (bits >> 8); buffer[offset + 4] = (byte) (bits); _offset = offset + 5; return; } long bits = Double.doubleToLongBits(value); buffer[offset + 0] = (byte) 'D'; buffer[offset + 1] = (byte) (bits >> 56); buffer[offset + 2] = (byte) (bits >> 48); buffer[offset + 3] = (byte) (bits >> 40); buffer[offset + 4] = (byte) (bits >> 32); buffer[offset + 5] = (byte) (bits >> 24); buffer[offset + 6] = (byte) (bits >> 16); buffer[offset + 7] = (byte) (bits >> 8); buffer[offset + 8] = (byte) (bits); _offset = offset + 9; } /** * Writes a date to the stream. * * <code><pre> * T b64 b56 b48 b40 b32 b24 b16 b8 * </pre></code> * * @param time the date in milliseconds from the epoch in UTC */ public void writeUTCDate(long time) throws IOException { if (SIZE < _offset + 32) flush(); int offset = _offset; byte []buffer = _buffer; buffer[offset++] = (byte) ('d'); buffer[offset++] = ((byte) (time >> 56)); buffer[offset++] = ((byte) (time >> 48)); buffer[offset++] = ((byte) (time >> 40)); buffer[offset++] = ((byte) (time >> 32)); buffer[offset++] = ((byte) (time >> 24)); buffer[offset++] = ((byte) (time >> 16)); buffer[offset++] = ((byte) (time >> 8)); buffer[offset++] = ((byte) (time)); _offset = offset; } /** * Writes a null value to the stream. * The null will be written with the following syntax * * <code><pre> * N * </pre></code> * * @param value the string value to write. */ public void writeNull() throws IOException { int offset = _offset; byte []buffer = _buffer; if (SIZE <= offset + 16) { flush(); offset = _offset; } buffer[offset++] = 'N'; _offset = offset; } /** * Writes a string value to the stream using UTF-8 encoding. * The string will be written with the following syntax: * * <code><pre> * S b16 b8 string-value * </pre></code> * * If the value is null, it will be written as * * <code><pre> * N * </pre></code> * * @param value the string value to write. */ public void writeString(String value) throws IOException { int offset = _offset; byte []buffer = _buffer; if (SIZE <= offset + 16) { flush(); offset = _offset; } if (value == null) { buffer[offset++] = (byte) 'N'; _offset = offset; } else { int length = value.length(); int strOffset = 0; while (length > 0x8000) { int sublen = 0x8000; offset = _offset; if (SIZE <= offset + 16) { flush(); offset = _offset; } // chunk can't end in high surrogate char tail = value.charAt(strOffset + sublen - 1); if (0xd800 <= tail && tail <= 0xdbff) sublen--; buffer[offset + 0] = (byte) 's'; buffer[offset + 1] = (byte) (sublen >> 8); buffer[offset + 2] = (byte) (sublen); _offset = offset + 3; printString(value, strOffset, sublen); length -= sublen; strOffset += sublen; } offset = _offset; if (SIZE <= offset + 16) { flush(); offset = _offset; } if (length <= STRING_DIRECT_MAX) { buffer[offset++] = (byte) (STRING_DIRECT + length); } else { buffer[offset++] = (byte) ('S'); buffer[offset++] = (byte) (length >> 8); buffer[offset++] = (byte) (length); } _offset = offset; printString(value, strOffset, length); } } /** * Writes a string value to the stream using UTF-8 encoding. * The string will be written with the following syntax: * * <code><pre> * S b16 b8 string-value * </pre></code> * * If the value is null, it will be written as * * <code><pre> * N * </pre></code> * * @param value the string value to write. */ public void writeString(char []buffer, int offset, int length) throws IOException { if (buffer == null) { if (SIZE < _offset + 16) flush(); _buffer[_offset++] = (byte) ('N'); } else { while (length > 0x8000) { int sublen = 0x8000; if (SIZE < _offset + 16) flush(); // chunk can't end in high surrogate char tail = buffer[offset + sublen - 1]; if (0xd800 <= tail && tail <= 0xdbff) sublen--; _buffer[_offset++] = (byte) 's'; _buffer[_offset++] = (byte) (sublen >> 8); _buffer[_offset++] = (byte) (sublen); printString(buffer, offset, sublen); length -= sublen; offset += sublen; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?