hessianoutput.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 950 行 · 第 1/2 页

JAVA
950
字号
   *   * @param value the double value to write.   */  public void writeDouble(double value)    throws IOException  {    long bits = Double.doubleToLongBits(value);        os.write('D');    os.write((byte) (bits >> 56));    os.write((byte) (bits >> 48));    os.write((byte) (bits >> 40));    os.write((byte) (bits >> 32));    os.write((byte) (bits >> 24));    os.write((byte) (bits >> 16));    os.write((byte) (bits >> 8));    os.write((byte) (bits));  }  /**   * 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  {    os.write('d');    os.write((byte) (time >> 56));    os.write((byte) (time >> 48));    os.write((byte) (time >> 40));    os.write((byte) (time >> 32));    os.write((byte) (time >> 24));    os.write((byte) (time >> 16));    os.write((byte) (time >> 8));    os.write((byte) (time));  }  /**   * 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  {    os.write('N');  }  /**   * 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  {    if (value == null) {      os.write('N');    }    else {      int length = value.length();      int offset = 0;            while (length > 0x8000) {        int sublen = 0x8000;	// chunk can't end in high surrogate	char tail = value.charAt(offset + sublen - 1);	if (0xd800 <= tail && tail <= 0xdbff)	  sublen--;                os.write('s');        os.write(sublen >> 8);        os.write(sublen);        printString(value, offset, sublen);        length -= sublen;        offset += sublen;      }      os.write('S');      os.write(length >> 8);      os.write(length);      printString(value, offset, 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) {      os.write('N');    }    else {      while (length > 0x8000) {        int sublen = 0x8000;	// chunk can't end in high surrogate	char tail = buffer[offset + sublen - 1];	if (0xd800 <= tail && tail <= 0xdbff)	  sublen--;                os.write('s');        os.write(sublen >> 8);        os.write(sublen);        printString(buffer, offset, sublen);        length -= sublen;        offset += sublen;      }      os.write('S');      os.write(length >> 8);      os.write(length);      printString(buffer, offset, length);    }  }  /**   * Writes a byte array to the stream.   * The array will be written with the following syntax:   *   * <code><pre>   * B b16 b18 bytes   * </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 writeBytes(byte []buffer)    throws IOException  {    if (buffer == null)      os.write('N');    else      writeBytes(buffer, 0, buffer.length);  }    /**   * Writes a byte array to the stream.   * The array will be written with the following syntax:   *   * <code><pre>   * B b16 b18 bytes   * </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 writeBytes(byte []buffer, int offset, int length)    throws IOException  {    if (buffer == null) {      os.write('N');    }    else {      while (length > 0x8000) {        int sublen = 0x8000;                os.write('b');        os.write(sublen >> 8);        os.write(sublen);        os.write(buffer, offset, sublen);        length -= sublen;        offset += sublen;      }      os.write('B');      os.write(length >> 8);      os.write(length);      os.write(buffer, offset, length);    }  }    /**   * Writes a byte buffer to the stream.   *   * <code><pre>   * </pre></code>   */  public void writeByteBufferStart()    throws IOException  {  }    /**   * Writes a byte buffer to the stream.   *   * <code><pre>   * b b16 b18 bytes   * </pre></code>   */  public void writeByteBufferPart(byte []buffer, int offset, int length)    throws IOException  {    while (length > 0) {      int sublen = length;      if (0x8000 < sublen)	sublen = 0x8000;      os.write('b');      os.write(sublen >> 8);      os.write(sublen);      os.write(buffer, offset, sublen);      length -= sublen;      offset += sublen;    }  }    /**   * Writes a byte buffer to the stream.   *   * <code><pre>   * b b16 b18 bytes   * </pre></code>   */  public void writeByteBufferEnd(byte []buffer, int offset, int length)    throws IOException  {    writeBytes(buffer, offset, length);  }  /**   * Writes a reference.   *   * <code><pre>   * R b32 b24 b16 b8   * </pre></code>   *   * @param value the integer value to write.   */  public void writeRef(int value)    throws IOException  {    os.write('R');    os.write(value >> 24);    os.write(value >> 16);    os.write(value >> 8);    os.write(value);  }  /**   * Writes a placeholder.   *   * <code><pre>   * P   * </pre></code>   */  public void writePlaceholder()    throws IOException  {    os.write('P');  }  /**   * If the object has already been written, just write its ref.   *   * @return true if we're writing a ref.   */  public boolean addRef(Object object)    throws IOException  {    if (_refs == null)      _refs = new IdentityHashMap();    Integer ref = (Integer) _refs.get(object);    if (ref != null) {      int value = ref.intValue();            writeRef(value);      return true;    }    else {      _refs.put(object, new Integer(_refs.size()));            return false;    }  }  /**   * Resets the references for streaming.   */  public void resetReferences()  {    if (_refs != null)      _refs.clear();  }  /**   * Removes a reference.   */  public boolean removeRef(Object obj)    throws IOException  {    if (_refs != null) {      _refs.remove(obj);      return true;    }    else      return false;  }  /**   * Replaces a reference from one object to another.   */  public boolean replaceRef(Object oldRef, Object newRef)    throws IOException  {    Integer value = (Integer) _refs.remove(oldRef);    if (value != null) {      _refs.put(newRef, value);      return true;    }    else      return false;  }  /**   * Prints a string to the stream, encoded as UTF-8 with preceeding length   *   * @param v the string to print.   */  public void printLenString(String v)    throws IOException  {    if (v == null) {      os.write(0);      os.write(0);    }    else {      int len = v.length();      os.write(len >> 8);      os.write(len);      printString(v, 0, len);    }  }  /**   * Prints a string to the stream, encoded as UTF-8   *   * @param v the string to print.   */  public void printString(String v)    throws IOException  {    printString(v, 0, v.length());  }    /**   * Prints a string to the stream, encoded as UTF-8   *   * @param v the string to print.   */  public void printString(String v, int offset, int length)    throws IOException  {    for (int i = 0; i < length; i++) {      char ch = v.charAt(i + offset);      if (ch < 0x80)        os.write(ch);      else if (ch < 0x800) {        os.write(0xc0 + ((ch >> 6) & 0x1f));        os.write(0x80 + (ch & 0x3f));      }      else {        os.write(0xe0 + ((ch >> 12) & 0xf));        os.write(0x80 + ((ch >> 6) & 0x3f));        os.write(0x80 + (ch & 0x3f));      }    }  }    /**   * Prints a string to the stream, encoded as UTF-8   *   * @param v the string to print.   */  public void printString(char []v, int offset, int length)    throws IOException  {    for (int i = 0; i < length; i++) {      char ch = v[i + offset];      if (ch < 0x80)        os.write(ch);      else if (ch < 0x800) {        os.write(0xc0 + ((ch >> 6) & 0x1f));        os.write(0x80 + (ch & 0x3f));      }      else {        os.write(0xe0 + ((ch >> 12) & 0xf));        os.write(0x80 + ((ch >> 6) & 0x3f));        os.write(0x80 + (ch & 0x3f));      }    }  }  public void flush()    throws IOException  {    if (this.os != null)      this.os.flush();  }  public void close()    throws IOException  {    if (this.os != null)      this.os.flush();  }}

⌨️ 快捷键说明

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