/** * Puts a byte into the buffer at the given position. Does * not increase the write position. * @param pos the position where to put the byte * @param b the byte to put */ public void putByte(int pos, byte b) { adaptSize(pos + 1); ByteBuffer bb = getBuffer(pos); int i = pos % _bufferSize; bb.put(i, b); }
/** * Puts a byte into the buffer at the given position. Does * not increase the write position. * @param pos the position where to put the byte * @param b the byte to put */ public void putByte(int pos, byte b) { adaptSize(pos + 1); ByteBuffer bb = getBuffer(pos); int i = pos % _bufferSize; bb.put(i, b); }
/** * Puts several bytes into the buffer at the given position. * Does not increase the write position. * @param pos the position where to put the bytes * @param bs an array of bytes to put */ public void putBytes(int pos, byte... bs) { adaptSize(pos + bs.length); ByteBuffer bb = null; int i = _bufferSize; for (byte b : bs) { if (i == _bufferSize) { bb = getBuffer(pos); i = pos % _bufferSize; } bb.put(i, b); ++i; ++pos; } }
/** * Puts several bytes into the buffer at the given position. * Does not increase the write position. * @param pos the position where to put the bytes * @param bs an array of bytes to put */ public void putBytes(int pos, byte... bs) { adaptSize(pos + bs.length); ByteBuffer bb = null; int i = _bufferSize; for (byte b : bs) { if (i == _bufferSize) { bb = getBuffer(pos); i = pos % _bufferSize; } bb.put(i, b); ++i; ++pos; } }
/** * 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); } } }
adaptSize(pos2); return pos2 - pos;
adaptSize(pos2); return pos2 - pos;
/** * 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 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); } } }