FileDocCategorySizeDatePackage
HeapByteBuffer.javaAPI DocJava SE 5 API9539Fri Aug 26 16:48:00 BST 2005java.nio

HeapByteBuffer

public class HeapByteBuffer extends ByteBuffer
A read/write HeapByteBuffer.

Fields Summary
Constructors Summary
HeapByteBuffer(int cap, int lim)

		// package-private

	super(-1, 0, lim, cap, new byte[cap], 0);
	/*
	hb = new byte[cap];
	offset = 0;
	*/




    
HeapByteBuffer(byte[] buf, int off, int len)

 // package-private

	super(-1, off, off + len, buf.length, buf, 0);
	/*
	hb = buf;
	offset = 0;
	*/




    
protected HeapByteBuffer(byte[] buf, int mark, int pos, int lim, int cap, int off)


	super(mark, pos, lim, cap, buf, off);
	/*
	hb = buf;
	offset = off;
	*/




    
Methods Summary
byte_get(int i)

				// package-private
	return hb[i];
    
void_put(int i, byte b)

			// package-private

	hb[i] = b;



    
public java.nio.CharBufferasCharBuffer()

	int size = this.remaining() >> 1;
	int off = offset + position();
	return (bigEndian
		? (CharBuffer)(new ByteBufferAsCharBufferB(this,
							       -1,
							       0,
							       size,
							       size,
							       off))
		: (CharBuffer)(new ByteBufferAsCharBufferL(this,
							       -1,
							       0,
							       size,
							       size,
							       off)));
    
public java.nio.DoubleBufferasDoubleBuffer()

	int size = this.remaining() >> 3;
	int off = offset + position();
	return (bigEndian
		? (DoubleBuffer)(new ByteBufferAsDoubleBufferB(this,
								   -1,
								   0,
								   size,
								   size,
								   off))
		: (DoubleBuffer)(new ByteBufferAsDoubleBufferL(this,
								   -1,
								   0,
								   size,
								   size,
								   off)));
    
public java.nio.FloatBufferasFloatBuffer()

	int size = this.remaining() >> 2;
	int off = offset + position();
	return (bigEndian
		? (FloatBuffer)(new ByteBufferAsFloatBufferB(this,
								 -1,
								 0,
								 size,
								 size,
								 off))
		: (FloatBuffer)(new ByteBufferAsFloatBufferL(this,
								 -1,
								 0,
								 size,
								 size,
								 off)));
    
public java.nio.IntBufferasIntBuffer()

	int size = this.remaining() >> 2;
	int off = offset + position();
	return (bigEndian
		? (IntBuffer)(new ByteBufferAsIntBufferB(this,
							     -1,
							     0,
							     size,
							     size,
							     off))
		: (IntBuffer)(new ByteBufferAsIntBufferL(this,
							     -1,
							     0,
							     size,
							     size,
							     off)));
    
public java.nio.LongBufferasLongBuffer()

	int size = this.remaining() >> 3;
	int off = offset + position();
	return (bigEndian
		? (LongBuffer)(new ByteBufferAsLongBufferB(this,
							       -1,
							       0,
							       size,
							       size,
							       off))
		: (LongBuffer)(new ByteBufferAsLongBufferL(this,
							       -1,
							       0,
							       size,
							       size,
							       off)));
    
public java.nio.ByteBufferasReadOnlyBuffer()


	return new HeapByteBufferR(hb,
				     this.markValue(),
				     this.position(),
				     this.limit(),
				     this.capacity(),
				     offset);



    
public java.nio.ShortBufferasShortBuffer()

	int size = this.remaining() >> 1;
	int off = offset + position();
	return (bigEndian
		? (ShortBuffer)(new ByteBufferAsShortBufferB(this,
								 -1,
								 0,
								 size,
								 size,
								 off))
		: (ShortBuffer)(new ByteBufferAsShortBufferL(this,
								 -1,
								 0,
								 size,
								 size,
								 off)));
    
public java.nio.ByteBuffercompact()


	System.arraycopy(hb, ix(position()), hb, ix(0), remaining());
	position(remaining());
	limit(capacity());
	return this;



    
public java.nio.ByteBufferduplicate()

	return new HeapByteBuffer(hb,
					this.markValue(),
					this.position(),
					this.limit(),
					this.capacity(),
					offset);
    
public java.nio.ByteBufferget(byte[] dst, int offset, int length)

	checkBounds(offset, length, dst.length);
	if (length > remaining())
	    throw new BufferUnderflowException();
	System.arraycopy(hb, ix(position()), dst, offset, length);
	position(position() + length);
	return this;
    
public byteget()

	return hb[ix(nextGetIndex())];
    
public byteget(int i)

	return hb[ix(checkIndex(i))];
    
public chargetChar()

	return Bits.getChar(this, ix(nextGetIndex(2)), bigEndian);
    
public chargetChar(int i)

	return Bits.getChar(this, ix(checkIndex(i, 2)), bigEndian);
    
public doublegetDouble()

	return Bits.getDouble(this, ix(nextGetIndex(8)), bigEndian);
    
public doublegetDouble(int i)

	return Bits.getDouble(this, ix(checkIndex(i, 8)), bigEndian);
    
public floatgetFloat()

	return Bits.getFloat(this, ix(nextGetIndex(4)), bigEndian);
    
public floatgetFloat(int i)

	return Bits.getFloat(this, ix(checkIndex(i, 4)), bigEndian);
    
public intgetInt()

	return Bits.getInt(this, ix(nextGetIndex(4)), bigEndian);
    
public intgetInt(int i)

	return Bits.getInt(this, ix(checkIndex(i, 4)), bigEndian);
    
public longgetLong()

	return Bits.getLong(this, ix(nextGetIndex(8)), bigEndian);
    
public longgetLong(int i)

	return Bits.getLong(this, ix(checkIndex(i, 8)), bigEndian);
    
public shortgetShort()

	return Bits.getShort(this, ix(nextGetIndex(2)), bigEndian);
    
public shortgetShort(int i)

	return Bits.getShort(this, ix(checkIndex(i, 2)), bigEndian);
    
public booleanisDirect()

	return false;
    
public booleanisReadOnly()

	return false;
    
protected intix(int i)

	return i + offset;
    
public java.nio.ByteBufferput(byte x)


	hb[ix(nextPutIndex())] = x;
	return this;



    
public java.nio.ByteBufferput(int i, byte x)


	hb[ix(checkIndex(i))] = x;
	return this;



    
public java.nio.ByteBufferput(byte[] src, int offset, int length)


	checkBounds(offset, length, src.length);
	if (length > remaining())
	    throw new BufferOverflowException();
	System.arraycopy(src, offset, hb, ix(position()), length);
	position(position() + length);
	return this;



    
public java.nio.ByteBufferput(java.nio.ByteBuffer src)


	if (src instanceof HeapByteBuffer) {
	    if (src == this)
		throw new IllegalArgumentException();
	    HeapByteBuffer sb = (HeapByteBuffer)src;
	    int n = sb.remaining();
	    if (n > remaining())
		throw new BufferOverflowException();
	    System.arraycopy(sb.hb, sb.ix(sb.position()),
			     hb, ix(position()), n);
	    sb.position(sb.position() + n);
	    position(position() + n);
	} else if (src.isDirect()) {
	    int n = src.remaining();
	    if (n > remaining())
		throw new BufferOverflowException();
	    src.get(hb, ix(position()), n);
	    position(position() + n);
	} else {
	    super.put(src);
	}
	return this;



    
public java.nio.ByteBufferputChar(char x)


	Bits.putChar(this, ix(nextPutIndex(2)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputChar(int i, char x)


	Bits.putChar(this, ix(checkIndex(i, 2)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputDouble(double x)


	Bits.putDouble(this, ix(nextPutIndex(8)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputDouble(int i, double x)


	Bits.putDouble(this, ix(checkIndex(i, 8)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputFloat(float x)


	Bits.putFloat(this, ix(nextPutIndex(4)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputFloat(int i, float x)


	Bits.putFloat(this, ix(checkIndex(i, 4)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputInt(int x)


	Bits.putInt(this, ix(nextPutIndex(4)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputInt(int i, int x)


	Bits.putInt(this, ix(checkIndex(i, 4)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputLong(long x)


	Bits.putLong(this, ix(nextPutIndex(8)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputLong(int i, long x)


	Bits.putLong(this, ix(checkIndex(i, 8)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputShort(short x)


	Bits.putShort(this, ix(nextPutIndex(2)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferputShort(int i, short x)


	Bits.putShort(this, ix(checkIndex(i, 2)), x, bigEndian);
	return this;



    
public java.nio.ByteBufferslice()

	return new HeapByteBuffer(hb,
					-1,
					0,
					this.remaining(),
					this.remaining(),
					this.position() + offset);