@Override public void write(int b) throws IOException { ensureSize(SIZE_OF_BYTE); buf[pos] = (byte) b; pos += SIZE_OF_BYTE; }
@Override public void writeShort(int v) throws IOException { ensureSize(SIZE_OF_SHORT); UNSAFE.putShort(buf, BYTE_ARRAY_OFFSET + pos, (short) v); pos += SIZE_OF_SHORT; }
@Override public void writeInt(int v) throws IOException { ensureSize(SIZE_OF_INT); UNSAFE.putInt(buf, BYTE_ARRAY_OFFSET + pos, v); pos += SIZE_OF_INT; }
@Override public void writeLong(long v) throws IOException { ensureSize(SIZE_OF_LONG); UNSAFE.putLong(buf, BYTE_ARRAY_OFFSET + pos, v); pos += SIZE_OF_LONG; }
@Override public void write(byte[] b) throws IOException { ensureSize(b.length); System.arraycopy(b, 0, buf, pos, b.length); pos += b.length; }
@Override public void write(byte[] b, int off, int len) throws IOException { ensureSize(len); System.arraycopy(b, off, buf, pos, len); pos += len; }
@Override public void writeByte(int v) throws IOException { ensureSize(SIZE_OF_BYTE); UNSAFE.putByte(buf, BYTE_ARRAY_OFFSET + pos, (byte) v); pos += SIZE_OF_BYTE; }
@Override public void writeBoolean(boolean v) throws IOException { ensureSize(SIZE_OF_BOOLEAN); UNSAFE.putBoolean(buf, BYTE_ARRAY_OFFSET + pos, v); pos += SIZE_OF_BOOLEAN; }
@Override public void writeFloat(float v) throws IOException { ensureSize(SIZE_OF_FLOAT); UNSAFE.putFloat(buf, BYTE_ARRAY_OFFSET + pos, v); pos += SIZE_OF_FLOAT; }
@Override public void writeChar(int v) throws IOException { ensureSize(SIZE_OF_CHAR); UNSAFE.putChar(buf, BYTE_ARRAY_OFFSET + pos, (char) v); pos += SIZE_OF_CHAR; }
@Override public void writeDouble(double v) throws IOException { ensureSize(SIZE_OF_DOUBLE); UNSAFE.putDouble(buf, BYTE_ARRAY_OFFSET + pos, v); pos += SIZE_OF_DOUBLE; }
@Override public void writeBytes(String s) throws IOException { // Note that this code is mostly copied from DataOutputStream int len = s.length(); ensureSize(len); for (int i = 0; i < len; i++) { int v = s.charAt(i); writeByte(v); } }
@Override public void writeChars(String s) throws IOException { // Note that this code is mostly copied from DataOutputStream int len = s.length(); ensureSize(len * SIZE_OF_CHAR); for (int i = 0; i < len; i++) { int v = s.charAt(i); writeChar(v); } }
ensureSize(utflen + SIZE_OF_SHORT); writeShort(utflen);