/** * Puts several bytes into the buffer at the given position * and increases the write position accordingly. * @param bs an array of bytes to put */ public void putBytes(byte... bs) { putBytes(_position, bs); _position += bs.length; }
/** * Puts several bytes into the buffer at the given position * and increases the write position accordingly. * @param bs an array of bytes to put */ public void putBytes(byte... bs) { putBytes(_position, bs); _position += bs.length; }
/** * Puts a character sequence into the buffer at the given * position. Does not increase the write position. * @param pos the position where to put the character sequence * @param s the character sequence to put */ public void putString(int pos, CharSequence s) { for (int i = 0; i < s.length(); ++i) { char c = s.charAt(i); byte b0 = (byte)c; byte b1 = (byte)(c >> 8); if (_order == ByteOrder.BIG_ENDIAN) { putBytes(pos, b1, b0); } else { putBytes(pos, b0, b1); } pos += 2; } }
/** * Puts a character sequence into the buffer at the given * position. Does not increase the write position. * @param pos the position where to put the character sequence * @param s the character sequence to put */ public void putString(int pos, CharSequence s) { for (int i = 0; i < s.length(); ++i) { char c = s.charAt(i); byte b0 = (byte)c; byte b1 = (byte)(c >> 8); if (_order == ByteOrder.BIG_ENDIAN) { putBytes(pos, b1, b0); } else { putBytes(pos, b0, b1); } pos += 2; } }
/** * Puts a 32-bit integer into the buffer at the given position. Does * not increase the write position. * @param pos the position where to put the integer * @param i the integer to put */ public void putInt(int pos, int i) { adaptSize(pos + 4); ByteBuffer bb = getBuffer(pos); int index = pos % _bufferSize; if (bb.limit() - index >= 4) { bb.putInt(index, i); } else { byte b0 = (byte)i; byte b1 = (byte)(i >> 8); byte b2 = (byte)(i >> 16); byte b3 = (byte)(i >> 24); if (_order == ByteOrder.BIG_ENDIAN) { putBytes(pos, b3, b2, b1, b0); } else { putBytes(pos, b0, b1, b2, b3); } } }
/** * Puts a 32-bit integer into the buffer at the given position. Does * not increase the write position. * @param pos the position where to put the integer * @param i the integer to put */ public void putInt(int pos, int i) { adaptSize(pos + 4); ByteBuffer bb = getBuffer(pos); int index = pos % _bufferSize; if (bb.limit() - index >= 4) { bb.putInt(index, i); } else { byte b0 = (byte)i; byte b1 = (byte)(i >> 8); byte b2 = (byte)(i >> 16); byte b3 = (byte)(i >> 24); if (_order == ByteOrder.BIG_ENDIAN) { putBytes(pos, b3, b2, b1, b0); } else { putBytes(pos, b0, b1, b2, b3); } } }
/** * Puts a 64-bit integer into the buffer at the given position. Does * not increase the write position. * @param pos the position where to put the integer * @param l the 64-bit integer to put */ public void putLong(int pos, long l) { adaptSize(pos + 8); ByteBuffer bb = getBuffer(pos); int index = pos % _bufferSize; if (bb.limit() - index >= 8) { bb.putLong(index, l); } else { byte b0 = (byte)l; byte b1 = (byte)(l >> 8); byte b2 = (byte)(l >> 16); byte b3 = (byte)(l >> 24); byte b4 = (byte)(l >> 32); byte b5 = (byte)(l >> 40); byte b6 = (byte)(l >> 48); byte b7 = (byte)(l >> 56); if (_order == ByteOrder.BIG_ENDIAN) { putBytes(pos, b7, b6, b5, b4, b3, b2, b1, b0); } else { putBytes(pos, b0, b1, b2, b3, b4, b5, b6, b7); } } }
/** * Puts a 64-bit integer into the buffer at the given position. Does * not increase the write position. * @param pos the position where to put the integer * @param l the 64-bit integer to put */ public void putLong(int pos, long l) { adaptSize(pos + 8); ByteBuffer bb = getBuffer(pos); int index = pos % _bufferSize; if (bb.limit() - index >= 8) { bb.putLong(index, l); } else { byte b0 = (byte)l; byte b1 = (byte)(l >> 8); byte b2 = (byte)(l >> 16); byte b3 = (byte)(l >> 24); byte b4 = (byte)(l >> 32); byte b5 = (byte)(l >> 40); byte b6 = (byte)(l >> 48); byte b7 = (byte)(l >> 56); if (_order == ByteOrder.BIG_ENDIAN) { putBytes(pos, b7, b6, b5, b4, b3, b2, b1, b0); } else { putBytes(pos, b0, b1, b2, b3, b4, b5, b6, b7); } } }