⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 largestringbuildervalue.java

📁 RESIN 3.2 最新源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  public final StringValue appendUnicode(char []buf, int offset, int length)  {    return append(buf, offset, length);  }    /**   * Append a Java string to the value.   */  @Override  public StringValue append(String s)  {    int len = s.length();        ensureCapacity(_length + len);        for (int i = 0; i < len; i++) {      _bufferList[_length / SIZE][_length % SIZE] = (byte) s.charAt(i);            _length++;    }        return this;  }    /**   * Append a Java buffer to the value.   */  @Override  public final StringValue append(char []buf, int offset, int length)  {    ensureCapacity(_length + length);    for (int i = offset; i < length + offset; i++) {      _bufferList[_length / SIZE][_length % SIZE] = (byte) buf[i];            _length++;    }    return this;  }  /**   * Append a buffer to the value.   */  public final StringValue append(byte []buf, int offset, int length)  {    ensureCapacity(_length + length);    while (length > 0) {      int chunk = _length / SIZE;      int chunkOffset = _length % SIZE;      int sublen = SIZE - chunkOffset;      if (length < sublen)	sublen = length;      System.arraycopy(buf, offset, _bufferList[chunk], chunkOffset, sublen);      offset += sublen;      length -= sublen;      _length += sublen;    }          return this;  }  /**   * Append a double to the value.   */  public final StringValue append(byte []buf)  {    return append(buf, 0, buf.length);  }  /**   * Append a Java byte to the value without conversions.   */  @Override  public final StringValue append(char v)  {    if (_length % SIZE == 0)      ensureCapacity(_length + 1);    _bufferList[_length / SIZE][_length % SIZE] = (byte) v;    _length += 1;    return this;  }  /**   * Append a Java byte to the value without conversions.   */  public final StringValue append(byte v)  {    if (_length % SIZE == 0)      ensureCapacity(_length + 1);    _bufferList[_length / SIZE][_length % SIZE] = (byte) v;    _length += 1;    return this;  }  /**   * Append a Java boolean to the value.   */  @Override  public final StringValue append(boolean v)  {    return append(v ? "true" : "false");  }  /**   * Append a Java long to the value.   */  @Override  public StringValue append(long v)  {    // XXX: this probably is frequent enough to special-case        return append(String.valueOf(v));  }  /**   * Append a Java double to the value.   */  @Override  public StringValue append(double v)  {    return append(String.valueOf(v));  }    /**   * Append a Java value to the value.   */  @Override  public final StringValue append(Value v)  {    v.appendTo(this);    return this;  }  /**   * Append from an input stream, using InputStream.read semantics,   * i.e. just call is.read once even if more data is available.   */  public int appendRead(InputStream is, long length)  {    try {      int offset = _length % SIZE;      if (offset == 0) {	ensureCapacity(_length + SIZE);      }            byte []buffer = _bufferList[_length / SIZE];      int sublen = SIZE - offset;      if (length < sublen)	sublen = (int) length;      sublen = is.read(buffer, 0, sublen);      if (sublen > 0) {	_length += sublen;	return sublen;      }      else	return -1;    } catch (IOException e) {      throw new QuercusRuntimeException(e);    }  }  /**   * Append from an input stream, reading from the input stream until   * end of file or the length is reached.   */  public int appendReadAll(InputStream is, long length)  {    int readLength = 0;        while (length > 0) {      int sublen = appendRead(is, length);      if (sublen < 0)	return readLength <= 0 ? -1 : readLength;      length -= sublen;      readLength += sublen;    }    return readLength;  }    /**   * Append to a string builder.   */  public StringValue appendTo(UnicodeBuilderValue sb)  {    if (length() == 0)      return sb;        Env env = Env.getInstance();    try {      Reader reader = env.getRuntimeEncodingFactory().create(toInputStream());            if (reader != null) {        sb.append(reader);        reader.close();      }      return sb;    } catch (IOException e) {      throw new QuercusRuntimeException(e);    }  }  //  // Java generator code  //  /**   * Prints the value.   * @param env   */  public void print(Env env)  {    for (int i = 0; i < _length; i += SIZE) {      int chunk = i / SIZE;      int sublen = _length - i;      if (SIZE < sublen)	sublen = SIZE;	      env.write(_bufferList[chunk], 0, sublen);    }  }  /**   * Prints the value.   * @param env   */  public void print(Env env, WriteStream out)  {    try {      for (int i = 0; i < _length; i += SIZE) {	int chunk = i / SIZE;	int sublen = _length - i;	if (SIZE < sublen)	  sublen = SIZE;		out.write(_bufferList[chunk], 0, sublen);      }    } catch (IOException e) {      throw new QuercusRuntimeException(e);    }  }  /**   * Serializes the value.   */  public void serialize(StringBuilder sb)  {    sb.append("s:");    sb.append(_length);    sb.append(":\"");    sb.append(toString());    sb.append("\";");  }  /**   * Returns an OutputStream.   */  public OutputStream getOutputStream()  {    return new BuilderOutputStream();  }  private void ensureCapacity(int newCapacity)  {    int chunk = _length / SIZE;    int endChunk = newCapacity / SIZE;    if (_bufferList.length <= endChunk) {      byte [][]bufferList = new byte[endChunk + 32][];      System.arraycopy(_bufferList, 0, bufferList, 0, _bufferList.length);      _bufferList = bufferList;    }    for (; chunk <= endChunk; chunk++) {      if (_bufferList[chunk] == null)	_bufferList[chunk] = new byte[SIZE];    }  }  /**   * Returns the hash code.   */  @Override  public int hashCode()  {    if (_hashCode != 0)      return _hashCode;        int hash = 37;    int length = _length;    byte [][]bufferList = _bufferList;    for (int i = 0; i < length; i++) {      hash = 65521 * hash + (bufferList[i / SIZE][i % SIZE] & 0xff);    }    _hashCode = hash;    return hash;  }  @Override  public String toDebugString()  {    StringBuilder sb = new StringBuilder();    int length = length();    sb.append("string(");    sb.append(length);    sb.append(") \"");    int appendLength = length > 256 ? 256 : length;    for (int i = 0; i < appendLength; i++)      sb.append(charAt(i));    if (length > 256)      sb.append(" ...");    sb.append('"');    return sb.toString();  }  @Override  public void varDumpImpl(Env env,                          WriteStream out,                          int depth,                          IdentityHashMap<Value, String> valueSet)    throws IOException  {    int length = length();    if (length < 0)        length = 0;        out.print("string(");    out.print(length);    out.print(") \"");    for (int i = 0; i < length; i++) {      int ch = charAt(i);      out.print((char) ch);    }    out.print("\"");        /*    int length = length();    if (length < 0)        length = 0;    out.print("string");        out.print("(");    out.print(length);    out.print(") \"");    for (int i = 0; i < length; i++) {      char ch = charAt(i);      if (0x20 <= ch && ch <= 0x7f || ch == '\t' || ch == '\r' || ch == '\n')        out.print(ch);      else if (ch <= 0xff)        out.print("\\x" + Integer.toHexString(ch / 16) + Integer.toHexString(ch % 16));      else {        out.print("\\u"		  + Integer.toHexString((ch >> 12) & 0xf)		  + Integer.toHexString((ch >> 8) & 0xf)		  + Integer.toHexString((ch >> 4) & 0xf)		  + Integer.toHexString((ch) & 0xf));      }    }    out.print("\"");    */  }  class BuilderInputStream extends InputStream {    private int _index;        /**     * Reads the next byte.     */    @Override    public int read()    {      if (_index < _length)	return charAt(_index++);      else	return -1;    }    /**     * Reads into a buffer.     */    @Override    public int read(byte []buffer, int offset, int length)    {      int sublen = _length - _index;      if (length < sublen)	sublen = length;      if (sublen <= 0)	return -1;      for (int i = 0; i < sublen; i++)	buffer[offset + i] = (byte) charAt(_index + i);      _index += sublen;      return sublen;    }  }  class BuilderOutputStream extends OutputStream {    /**     * Writes the next byte.     */    @Override    public void write(int ch)    {      append(ch);    }    /**     * Reads into a buffer.     */    @Override    public void write(byte []buffer, int offset, int length)    {      append(buffer, offset, length);    }  }}

⌨️ 快捷键说明

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