Ejemplo n.º 1
0
  public void writeString(String s) {
    int length = s.length();

    boolean asciiCode = true;

    for (int i = 0; i < length; i++) {
      char c = s.charAt(i);

      if ((c == 0) || (c > 127)) {
        asciiCode = false;
        break;
      }
    }

    if (asciiCode) {
      byte[] buffer = getBuffer(length + 5);

      BigEndianCodec.putBoolean(buffer, index++, asciiCode);

      BigEndianCodec.putInt(buffer, index, length);

      index += 4;

      for (int i = 0; i < length; i++) {
        char c = s.charAt(i);

        buffer[index++] = (byte) c;
      }
    } else {
      byte[] buffer = getBuffer(length * 2 + 5);

      BigEndianCodec.putBoolean(buffer, index++, asciiCode);

      BigEndianCodec.putInt(buffer, index, length);

      index += 4;

      for (int i = 0; i < length; i++) {
        char c = s.charAt(i);

        BigEndianCodec.putChar(buffer, index, c);

        index += 2;
      }
    }
  }
Ejemplo n.º 2
0
 public void writeBoolean(boolean b) {
   BigEndianCodec.putBoolean(getBuffer(1), index++, b);
 }
Ejemplo n.º 3
0
  public void writeShort(short s) {
    BigEndianCodec.putShort(getBuffer(2), index, s);

    index += 2;
  }
Ejemplo n.º 4
0
  public void writeLong(long l) {
    BigEndianCodec.putLong(getBuffer(8), index, l);

    index += 8;
  }
Ejemplo n.º 5
0
  public void writeInt(int i) {
    BigEndianCodec.putInt(getBuffer(4), index, i);

    index += 4;
  }
Ejemplo n.º 6
0
  public void writeFloat(float f) {
    BigEndianCodec.putFloat(getBuffer(4), index, f);

    index += 4;
  }
Ejemplo n.º 7
0
  public void writeDouble(double d) {
    BigEndianCodec.putDouble(getBuffer(8), index, d);

    index += 8;
  }
Ejemplo n.º 8
0
  public void writeChar(char c) {
    BigEndianCodec.putChar(getBuffer(2), index, c);

    index += 2;
  }