burlapinput.java

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

JAVA
1,810
字号
   */  public float readFloat()    throws IOException  {    return (float) readDouble();  }  /**   * Reads a double   *   * <pre>   * &lt;double>value&lt;/double>   * </pre>   */  public double readDouble()    throws IOException  {    int tag = parseTag();    double value;    switch (tag) {    case TAG_NULL:      value = 0;      expectTag(TAG_NULL_END);      return value;          case TAG_BOOLEAN:      value = parseInt();      expectTag(TAG_BOOLEAN_END);      return value;          case TAG_INT:      value = parseInt();      expectTag(TAG_INT_END);      return value;          case TAG_LONG:      value = parseLong();      expectTag(TAG_LONG_END);      return value;          case TAG_DOUBLE:      value = parseDouble();      expectTag(TAG_DOUBLE_END);      return value;          default:      throw expectedTag("double", tag);    }  }  /**   * Reads a date.   *   * <pre>   * &lt;date>ISO-8609 date&lt;/date>   * </pre>   */  public long readUTCDate()    throws IOException  {    int tag = parseTag();    if (tag != TAG_DATE)      throw error("expected date");    if (_utcCalendar == null)      _utcCalendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));    long value = parseDate(_utcCalendar);    expectTag(TAG_DATE_END);    return value;  }  /**   * Reads a date.   *   * <pre>   * &lt;date>ISO-8609 date&lt;/date>   * </pre>   */  public long readLocalDate()    throws IOException  {    int tag = parseTag();    if (tag != TAG_DATE)      throw error("expected date");    if (_localCalendar == null)      _localCalendar = Calendar.getInstance();    long value = parseDate(_localCalendar);    expectTag(TAG_DATE_END);    return value;  }  /**   * Reads a string   *   * <pre>   * &lt;string>value&lt;/string>   * </pre>   */  public String readString()    throws IOException  {    int tag = parseTag();    String value;        switch (tag) {    case TAG_NULL:      expectTag(TAG_NULL_END);      return null;    case TAG_STRING:      _sbuf.setLength(0);      value = parseString(_sbuf).toString();      expectTag(TAG_STRING_END);      return value;    case TAG_XML:      _sbuf.setLength(0);      value = parseString(_sbuf).toString();      expectTag(TAG_XML_END);      return value;    default:      throw expectedTag("string", tag);    }  }  /**   * Reads an XML node.   *   * <pre>   * &xml;xml string&lt;/xml>   * </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':      throw error("can't cope");    default:      throw expectedTag("string", tag);    }  }  /**   * Reads a byte array   *   * <pre>   * &lt;base64>...&lt;/base64>   * </pre>   */  public byte []readBytes()    throws IOException  {    int tag = parseTag();    switch (tag) {    case TAG_NULL:      expectTag(TAG_NULL_END);      return null;    case TAG_BASE64:      byte []data = parseBytes();      expectTag(TAG_BASE64_END);      return data;          default:      throw expectedTag("bytes", tag);    }  }  /**   * Reads a length   *   * <pre>   * &lt;length>value&lt;/length>   * </pre>   */  public int readLength()    throws IOException  {    int tag = parseTag();    if (tag != TAG_LENGTH) {      _peekTag = tag;      return -1;    }    int value = parseInt();    expectTag(TAG_LENGTH_END);    return value;  }  /**   * Reads a fault.   */  private HashMap readFault()    throws IOException  {    HashMap map = new HashMap();    int code = parseTag();    for (; code >= 0 && code != TAG_FAULT_END; code = parseTag()) {      _peekTag = code;            Object key = readObject();      Object value = readObject();      if (key != null && value != null)        map.put(key, value);    }    if (code != TAG_FAULT_END)      throw expectedTag("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.equals(Object.class))      return readObject();        int tag = parseTag();    switch (tag) {    case TAG_NULL:      expectTag(TAG_NULL_END);      return null;    case TAG_MAP:    {      String type = readType();      Deserializer reader;            reader = _serializerFactory.getObjectDeserializer(type, cl);      return reader.readMap(this);    }    case TAG_LIST:    {      String type = readType();      int length = readLength();            Deserializer reader;      reader = _serializerFactory.getObjectDeserializer(type, cl);      return reader.readList(this, length);    }    case TAG_REF:    {      int ref = parseInt();      expectTag(TAG_REF_END);      return _refs.get(ref);    }    case TAG_REMOTE:    {      String type = readType();      String url = readString();      expectTag(TAG_REMOTE_END);      Object remote = resolveRemote(type, url);            return remote;    }    }        _peekTag = tag;    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 = parseTag();    switch (tag) {    case TAG_NULL:      expectTag(TAG_NULL_END);      return null;          case TAG_BOOLEAN:    {      int value = parseInt();      expectTag(TAG_BOOLEAN_END);      return new Boolean(value != 0);    }        case TAG_INT:    {      int value = parseInt();      expectTag(TAG_INT_END);      return new Integer(value);    }        case TAG_LONG:    {      long value = parseLong();      expectTag(TAG_LONG_END);      return new Long(value);    }        case TAG_DOUBLE:    {      double value = parseDouble();      expectTag(TAG_DOUBLE_END);      return new Double(value);    }        case TAG_DATE:    {      long value = parseDate();      expectTag(TAG_DATE_END);      return new Date(value);    }        case TAG_XML:    {      return parseXML();    }    case TAG_STRING:    {      _sbuf.setLength(0);      String value = parseString(_sbuf).toString();      expectTag(TAG_STRING_END);      return value;    }    case TAG_BASE64:    {      byte []data = parseBytes();      expectTag(TAG_BASE64_END);      return data;    }    case TAG_LIST:    {      String type = readType();      int length = readLength();      return _serializerFactory.readList(this, length, type);    }    case TAG_MAP:    {      String type = readType();      Deserializer deserializer;      deserializer = _serializerFactory.getObjectDeserializer(type);      return deserializer.readMap(this);    }    case TAG_REF:    {      int ref = parseInt();      expectTag(TAG_REF_END);      return _refs.get(ref);    }    case TAG_REMOTE:    {      String type = readType();      String url = readString();      expectTag(TAG_REMOTE_END);      return resolveRemote(type, url);    }    default:      throw error("unknown code:" + tagName(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 parseTag();  }  /**   * Reads the start of a map.   */  public int readMapStart()    throws IOException  {    return parseTag();  }  /**   * Returns true if this is the end of a list or a map.   */  public boolean isEnd()    throws IOException  {    int code = parseTag();    _peekTag = code;    return (code < 0 || code >= 100);  }  /**   * Reads the end byte.   */  public void readEnd()    throws IOException  {    int code = parseTag();    if (code < 100)      throw error("unknown code:" + (char) code);  }  /**   * Reads the end of the map   */  public void readMapEnd()    throws IOException  {    expectTag(TAG_MAP_END);  }  /**   * Reads the end of the map   */  public void readListEnd()    throws IOException  {    expectTag(TAG_LIST_END);  }  /**   * 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);  }  /**   * 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 BurlapRemote(type, url);  }  /**   * Parses a type from the stream.   *   * <pre>   * &lt;type>type&lt;/type>   * </pre>   */  public String readType()    throws IOException  {    int code = parseTag();    if (code != TAG_TYPE) {      _peekTag = code;      return "";    }    _sbuf.setLength(0);    int ch;    while ((ch = readChar()) >= 0)      _sbuf.append((char) ch);    String type = _sbuf.toString();        expectTag(TAG_TYPE_END);    return type;  }  /**   * Parses a 32-bit integer value from the stream.   */  private int parseInt()    throws IOException  {    int sign = 1;    int ch = read();    if (ch == '-') {      sign = -1;      ch = read();    }    int value = 0;    for (; ch >= '0' && ch <= '9'; ch = read())      value = 10 * value + ch - '0';    _peek = ch;    return sign * value;  }  /**   * Parses a 64-bit long value from the stream.   */  private long parseLong()    throws IOException  {    int sign = 1;    int ch = read();    if (ch == '-') {      sign = -1;      ch = read();    }

⌨️ 快捷键说明

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