Пример #1
0
  @Override
  public void write(final OutputStream output) throws IOException {
    if (!isValid()) return;

    super.write(output);

    final int byteCount;
    if (getHeaderType() == QDefines.QBYTE_BUFFER_TYPE8) {
      QUtils.writeByte(value.length, output);
      byteCount = getInternalSize() - 1;
    } else {
      assert (getHeaderType() == QDefines.QBYTE_BUFFER_TYPE16);
      QUtils.writeWord(value.length, output);
      byteCount = getInternalSize() - 2;
    }

    output.write(value, 0, byteCount);
  }
Пример #2
0
  public void parse(final InputStream stream) throws IOException {
    final int type = QUtils.readByte(stream);

    final int length;
    if (type == QDefines.QBYTE_BUFFER_TYPE8) {
      length = QUtils.readByte(stream);
    } else if (type == QDefines.QBYTE_BUFFER_TYPE16) {
      length = QUtils.readWord(stream);
    } else {
      throw new QCWException("Unsupported Byte Buffer Type: 0x" + Integer.toHexString(type));
    }

    final byte[] bytes = new byte[length];
    final int readBytes = stream.read(bytes, 0, length);
    assert (readBytes == length);

    setValue(bytes);
  }