hessianinput.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,701 行 · 第 1/3 页

JAVA
1,701
字号
  {    return (float) readDouble();  }  /**   * Reads a double   *   * <pre>   * D b64 b56 b48 b40 b32 b24 b16 b8   * </pre>   */  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 date.   *   * <pre>   * T b64 b56 b48 b40 b32 b24 b16 b8   * </pre>   */  public long readUTCDate()    throws IOException  {    int tag = read();    if (tag != 'd')      throw error("expected date at " + codeName(tag));    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);  }  /**   * Reads a byte from the stream.   */  public int readChar()    throws IOException  {    if (_chunkLength > 0) {      _chunkLength--;      if (_chunkLength == 0 && _isLastChunk)        _chunkLength = END_OF_DATA;      int ch = parseUTF8Char();      return ch;    }    else if (_chunkLength == END_OF_DATA) {      _chunkLength = 0;      return -1;    }        int tag = read();    switch (tag) {    case 'N':      return -1;    case 'S':    case 's':    case 'X':    case 'x':      _isLastChunk = tag == 'S' || tag == 'X';      _chunkLength = (read() << 8) + read();      _chunkLength--;      int value = parseUTF8Char();      // special code so successive read byte won't      // be read as a single object.      if (_chunkLength == 0 && _isLastChunk)        _chunkLength = END_OF_DATA;      return value;          default:      throw new IOException("expected 'S' at " + (char) tag);    }  }  /**   * Reads a byte array from the stream.   */  public int readString(char []buffer, int offset, int length)    throws IOException  {    int readLength = 0;    if (_chunkLength == END_OF_DATA) {      _chunkLength = 0;      return -1;    }    else if (_chunkLength == 0) {      int tag = read();      switch (tag) {      case 'N':        return -1;            case 'S':      case 's':      case 'X':      case 'x':        _isLastChunk = tag == 'S' || tag == 'X';        _chunkLength = (read() << 8) + read();        break;      default:        throw new IOException("expected 'S' at " + (char) tag);      }    }    while (length > 0) {      if (_chunkLength > 0) {        buffer[offset++] = (char) parseUTF8Char();        _chunkLength--;        length--;        readLength++;      }      else if (_isLastChunk) {        if (readLength == 0)          return -1;        else {          _chunkLength = END_OF_DATA;          return readLength;        }      }      else {        int tag = read();        switch (tag) {        case 'S':        case 's':        case 'X':        case 'x':          _isLastChunk = tag == 'S' || tag == 'X';          _chunkLength = (read() << 8) + read();          break;              default:          throw new IOException("expected 'S' at " + (char) tag);        }      }    }        if (readLength == 0)      return -1;    else if (_chunkLength > 0 || ! _isLastChunk)      return readLength;    else {      _chunkLength = END_OF_DATA;      return readLength;    }  }  /**   * Reads a string   *   * <pre>   * S b16 b8 string value   * </pre>   */  public String readString()    throws IOException  {    int tag = read();    switch (tag) {    case 'N':      return null;    case 'I':      return String.valueOf(parseInt());    case 'L':      return String.valueOf(parseLong());    case 'D':      return String.valueOf(parseDouble());    case 'S':    case 's':    case 'X':    case 'x':      _isLastChunk = tag == 'S' || tag == 'X';      _chunkLength = (read() << 8) + read();      _sbuf.setLength(0);      int ch;      while ((ch = parseChar()) >= 0)        _sbuf.append((char) ch);      return _sbuf.toString();    default:      throw expect("string", tag);    }  }  /**   * Reads an XML node.   *   * <pre>   * S b16 b8 string value   * </pre>   */  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 byte array   *   * <pre>   * B b16 b8 data value   * </pre>   */  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);    }  }  /**   * Reads a byte from the stream.   */  public int readByte()    throws IOException  {    if (_chunkLength > 0) {      _chunkLength--;      if (_chunkLength == 0 && _isLastChunk)        _chunkLength = END_OF_DATA;      return read();    }    else if (_chunkLength == END_OF_DATA) {      _chunkLength = 0;      return -1;    }        int tag = read();    switch (tag) {    case 'N':      return -1;    case 'B':    case 'b':      _isLastChunk = tag == 'B';      _chunkLength = (read() << 8) + read();      int value = parseByte();      // special code so successive read byte won't      // be read as a single object.      if (_chunkLength == 0 && _isLastChunk)        _chunkLength = END_OF_DATA;      return value;          default:      throw new IOException("expected 'B' at " + (char) tag);    }  }  /**   * Reads a byte array from the stream.   */  public int readBytes(byte []buffer, int offset, int length)    throws IOException  {    int readLength = 0;    if (_chunkLength == END_OF_DATA) {      _chunkLength = 0;      return -1;    }    else if (_chunkLength == 0) {      int tag = read();      switch (tag) {      case 'N':        return -1;            case 'B':      case 'b':        _isLastChunk = tag == 'B';        _chunkLength = (read() << 8) + read();        break;            default:        throw new IOException("expected 'B' at " + (char) tag);      }    }    while (length > 0) {      if (_chunkLength > 0) {        buffer[offset++] = (byte) read();        _chunkLength--;        length--;        readLength++;      }      else if (_isLastChunk) {        if (readLength == 0)          return -1;        else {          _chunkLength = END_OF_DATA;          return readLength;        }      }      else {        int tag = read();        switch (tag) {        case 'B':        case 'b':          _isLastChunk = tag == 'B';          _chunkLength = (read() << 8) + read();          break;              default:          throw new IOException("expected 'B' at " + (char) tag);        }      }    }        if (readLength == 0)      return -1;    else if (_chunkLength > 0 || ! _isLastChunk)      return readLength;    else {      _chunkLength = END_OF_DATA;      return readLength;    }  }  /**   * 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 object from the input stream with an expected type.   */  public Object readObject(Class cl)    throws IOException  {    if (cl == null || cl == Object.class)      return readObject();        int tag = read();        switch (tag) {    case 'N':      return null;    case 'M':    {      String type = readType();      // hessian/3386      if ("".equals(type)) {	Deserializer reader;	reader = _serializerFactory.getDeserializer(cl);	return reader.readMap(this);      }      else {	Deserializer reader;	reader = _serializerFactory.getObjectDeserializer(type);        return reader.readMap(this);      }    }    case 'V':    {      String type = readType();      int length = readLength();            Deserializer reader;      reader = _serializerFactory.getObjectDeserializer(type);            if (cl != reader.getType() && cl.isAssignableFrom(reader.getType()))        return reader.readList(this, length);      reader = _serializerFactory.getDeserializer(cl);      Object v = reader.readList(this, length);      return v;    }    case 'R':    {      int ref = parseInt();      return _refs.get(ref);    }    case 'r':    {      String type = readType();      String url = readString();      return resolveRemote(type, url);    }    }    _peek = tag;    // hessian/332i vs hessian/3406    //return readObject();        Object value = _serializerFactory.getDeserializer(cl).readObject(this);    return value;  }    /**   * Reads an arbitrary object from the input stream when the type   * is unknown.   */  public Object readObject()    throws IOException  {    int tag = read();    switch (tag) {    case 'N':      return null;          case 'T':      return Boolean.valueOf(true);          case 'F':      return Boolean.valueOf(false);          case 'I':      return Integer.valueOf(parseInt());        case 'L':      return Long.valueOf(parseLong());        case 'D':      return Double.valueOf(parseDouble());        case 'd':      return new Date(parseLong());        case 'x':    case 'X': {      _isLastChunk = tag == 'X';      _chunkLength = (read() << 8) + read();      return parseXML();    }    case 's':    case 'S': {      _isLastChunk = tag == 'S';      _chunkLength = (read() << 8) + read();      int data;      _sbuf.setLength(0);            while ((data = parseChar()) >= 0)        _sbuf.append((char) data);      return _sbuf.toString();    }    case 'b':    case 'B': {      _isLastChunk = tag == 'B';      _chunkLength = (read() << 8) + read();      int data;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?