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; } } }
public void writeBoolean(boolean b) { BigEndianCodec.putBoolean(getBuffer(1), index++, b); }
public void writeShort(short s) { BigEndianCodec.putShort(getBuffer(2), index, s); index += 2; }
public void writeLong(long l) { BigEndianCodec.putLong(getBuffer(8), index, l); index += 8; }
public void writeInt(int i) { BigEndianCodec.putInt(getBuffer(4), index, i); index += 4; }
public void writeFloat(float f) { BigEndianCodec.putFloat(getBuffer(4), index, f); index += 4; }
public void writeDouble(double d) { BigEndianCodec.putDouble(getBuffer(8), index, d); index += 8; }
public void writeChar(char c) { BigEndianCodec.putChar(getBuffer(2), index, c); index += 2; }