IntViewBufferImpl.java [plain text]
package java.nio;
final class IntViewBufferImpl extends IntBuffer
{
private int offset;
private ByteBuffer bb;
private boolean readOnly;
private ByteOrder endian;
IntViewBufferImpl (ByteBuffer bb, int capacity)
{
super (capacity, capacity, 0, -1);
this.bb = bb;
this.offset = bb.position();
this.readOnly = bb.isReadOnly();
this.endian = bb.order();
}
public IntViewBufferImpl (ByteBuffer bb, int offset, int capacity,
int limit, int position, int mark,
boolean readOnly, ByteOrder endian)
{
super (capacity, limit, position, mark);
this.bb = bb;
this.offset = offset;
this.readOnly = readOnly;
this.endian = endian;
}
public int get ()
{
int p = position();
int result = ByteBufferHelper.getInt(bb, (p << 2) + offset, endian);
position(p + 1);
return result;
}
public int get (int index)
{
return ByteBufferHelper.getInt(bb, (index << 2) + offset, endian);
}
public IntBuffer put (int value)
{
int p = position();
ByteBufferHelper.putInt(bb, (p << 2) + offset, value, endian);
position(p + 1);
return this;
}
public IntBuffer put (int index, int value)
{
ByteBufferHelper.putInt(bb, (index << 2) + offset, value, endian);
return this;
}
public IntBuffer compact ()
{
if (position () > 0)
{
int count = limit () - position ();
bb.shiftDown(offset, offset + 4 * position(), 4 * count);
position (count);
limit (capacity ());
}
return this;
}
public IntBuffer slice ()
{
return new IntViewBufferImpl (bb, (position () >> 2) + offset,
remaining(), remaining(), 0, -1,
readOnly, endian);
}
IntBuffer duplicate (boolean readOnly)
{
int pos = position();
reset();
int mark = position();
position(pos);
return new IntViewBufferImpl (bb, offset, capacity(), limit(),
pos, mark, readOnly, endian);
}
public IntBuffer duplicate ()
{
return duplicate(readOnly);
}
public IntBuffer asReadOnlyBuffer ()
{
return duplicate(true);
}
public boolean isReadOnly ()
{
return readOnly;
}
public boolean isDirect ()
{
return bb.isDirect ();
}
public ByteOrder order ()
{
return endian;
}
}