@Override public void writeShort(int v) throws IOException { if (this.position >= this.buffer.length - 1) { resize(2); } this.buffer[this.position++] = (byte) ((v >>> 8) & 0xff); this.buffer[this.position++] = (byte) ((v >>> 0) & 0xff); }
@Override public void write(int b) throws IOException { if (this.position >= this.buffer.length) { resize(1); } this.buffer[this.position++] = (byte) (b & 0xff); }
@Override public void writeChar(int v) throws IOException { if (this.position >= this.buffer.length - 1) { resize(2); } this.buffer[this.position++] = (byte) (v >> 8); this.buffer[this.position++] = (byte) v; }
@SuppressWarnings("restriction") @Override public void writeLong(long v) throws IOException { if (this.position >= this.buffer.length - 7) { resize(8); } if (LITTLE_ENDIAN) { v = Long.reverseBytes(v); } UNSAFE.putLong(this.buffer, BASE_OFFSET + this.position, v); this.position += 8; }
@Override public void write(byte[] b, int off, int len) throws IOException { if (len < 0 || off > b.length - len) { throw new ArrayIndexOutOfBoundsException(); } if (this.position > this.buffer.length - len) { resize(len); } System.arraycopy(b, off, this.buffer, this.position, len); this.position += len; }
@SuppressWarnings("restriction") @Override public void writeInt(int v) throws IOException { if (this.position >= this.buffer.length - 3) { resize(4); } if (LITTLE_ENDIAN) { v = Integer.reverseBytes(v); } UNSAFE.putInt(this.buffer, BASE_OFFSET + this.position, v); this.position += 4; }
@Override public void writeBytes(String s) throws IOException { final int sLen = s.length(); if (this.position >= this.buffer.length - sLen) { resize(sLen); } for (int i = 0; i < sLen; i++) { writeByte(s.charAt(i)); } this.position += sLen; }
@Override public void writeChars(String s) throws IOException { final int sLen = s.length(); if (this.position >= this.buffer.length - 2*sLen) { resize(2*sLen); } for (int i = 0; i < sLen; i++) { writeChar(s.charAt(i)); } }
resize(utflen + 2);