/** * @see ByteBuffer#clear() */ public IoBuffer clear() { position = getPointerByPosition(0); limit = getPointerByPosition(capacity); mark = null; return this; }
/** * @see ByteBuffer#flip() */ public IoBuffer flip() { limit = position; position = getPointerByPosition(0); return this; }
/** * @see ByteBuffer#limit(int) */ public void limit(int newLimit) { this.limit = getPointerByPosition(newLimit); }
/** * @see ByteBuffer#putInt(int, int) */ public IoBuffer putInt(int index, int value) { return putInt(getPointerByPosition(index), value); }
/** * @see ByteBuffer#getChar(int) */ public char getChar(int index) { return getChar(getPointerByPosition(index)); }
/** * @see ByteBuffer#getDouble(int) */ public double getDouble(int index) { return getDouble(getPointerByPosition(index)); }
/** * @see ByteBuffer#getInt(int) */ public int getInt(int index) { return getInt(getPointerByPosition(index)); }
/** * @see ByteBuffer#putChar(int, char) */ public IoBuffer putChar(int index, char value) { return putChar(getPointerByPosition(index), value); }
/** * @see ByteBuffer#rewind() */ public IoBuffer rewind() { position(0); mark = getPointerByPosition(-1); return this; }
/** * @see ByteBuffer#getFloat(int) */ public float getFloat(int index) { return getFloat(getPointerByPosition(index)); }
/** * @see ByteBuffer#putLong(int, long) */ public IoBuffer putLong(int index, long value) { return putLong(getPointerByPosition(index), value); }
/** * @see ByteBuffer#putShort(int, short) */ public IoBuffer putShort(int index, short value) { return putShort(getPointerByPosition(index), value); }
/** * @see ByteBuffer#getLong(int) */ public long getLong(int index) { return getLong(getPointerByPosition(index)); }
/** * @see ByteBuffer#getShort(int) */ public long getShort(int index) { return getShort(getPointerByPosition(index)); }
/** * @see ByteBuffer#putDouble(int, double) */ public IoBuffer putDouble(int index, double value) { return putDouble(getPointerByPosition(index), value); }
/** * @see ByteBuffer#putFloat(int, float) */ public IoBuffer putFloat(int index, float value) { return putFloat(getPointerByPosition(index), value); }
/** * @see ByteBuffer#put(int, byte) */ public IoBuffer put(int index, byte value) { if (index >= limit.getPosition()) { throw new IndexOutOfBoundsException(); } Pointer p = getPointerByPosition(index); put(p, value); return this; }
/** * @see ByteBuffer#get(int) */ public byte get(int index) { if (index >= limit.getPosition()) { throw new IndexOutOfBoundsException(); } return get(getPointerByPosition(index)); }
private void enqueue(ByteBuffer buffer) { if (buffer.isReadOnly()) { readonly = true; } if (!buffer.isDirect()) { direct = false; } if (buffer.remaining() > 0) { BufferNode newnode = new BufferNode(buffer, capacity); capacity += buffer.capacity(); if (head == null) { head = newnode; position = getPointerByPosition(0); } else { tail.setNext(newnode); } tail = newnode; limit = getPointerByPosition(capacity); } }
/** * Returns a copy of the current {@link IoBuffer}, with an independent copy * of the position, limit and mark. * * @return the copied {@link IoBuffer} */ public IoBuffer duplicate() { IoBuffer buffer = new IoBuffer(); for (BufferNode node = head; node != null; node = node.getNext()) { ByteBuffer byteBuffer = node.getBuffer().duplicate(); byteBuffer.rewind(); buffer.enqueue(byteBuffer); } buffer.position(position()); buffer.limit(limit()); buffer.mark = mark != null ? getPointerByPosition(mark.getPosition()) : null; buffer.readonly = readonly; return buffer; }