Code example for Buffer

Methods: getClass, position

0
	} 
 
	public static void copy(Buffer src, Buffer dst, int numElements) {
		if (useLoonNative) {
			int numBytes = elementsToBytes(src, numElements);
			bufferCopy(src, positionInBytes(src), dst, positionInBytes(dst),
					numBytes);
			dst.limit(dst.position() + bytesToElements(dst, numBytes));
		} else { 
			putBuffer(dst, src, numElements);
		} 
	} 
 
	private static int positionInBytes(Buffer dst) {
		if (dst instanceof ByteBuffer) {
			return dst.position();
		} else if (dst instanceof ShortBuffer) {
			return dst.position() << SIZEOF_BYTE;
		} else if (dst instanceof CharBuffer) {
			return dst.position() << SIZEOF_BYTE;
		} else if (dst instanceof IntBuffer) {
			return dst.position() << SIZEOF_SHORT;
		} else if (dst instanceof LongBuffer) {
			return dst.position() << 3;
		} else if (dst instanceof FloatBuffer) {
			return dst.position() << SIZEOF_SHORT;
		} else if (dst instanceof DoubleBuffer) {
			return dst.position() << 3;
		} else { 
			throw new RuntimeException("Can't copy to a "
					+ dst.getClass().getName() + " instance");
		} 
	} 
 
	private static int bytesToElements(Buffer dst, int bytes) {
		if (dst instanceof ByteBuffer) {
			return bytes;
		} else if (dst instanceof ShortBuffer) {
			return bytes >>> SIZEOF_BYTE;
		} else if (dst instanceof CharBuffer) {
			return bytes >>> SIZEOF_BYTE;
		} else if (dst instanceof IntBuffer) {
			return bytes >>> SIZEOF_SHORT;
		} else if (dst instanceof LongBuffer) {
			return bytes >>> 3;
		} else if (dst instanceof FloatBuffer) {
			return bytes >>> SIZEOF_SHORT;
		} else if (dst instanceof DoubleBuffer) {
			return bytes >>> 3;
		} else { 
			throw new RuntimeException("Can't copy to a "
					+ dst.getClass().getName() + " instance");
		} 
	} 
 
	private static int elementsToBytes(Buffer dst, int elements) {
		if (dst instanceof ByteBuffer) {
			return elements;
		} else if (dst instanceof ShortBuffer) {
			return elements << SIZEOF_BYTE;
		} else if (dst instanceof CharBuffer) {
			return elements << SIZEOF_BYTE;
		} else if (dst instanceof IntBuffer) {
			return elements << SIZEOF_SHORT;
		} else if (dst instanceof LongBuffer) {
			return elements << 3;
		} else if (dst instanceof FloatBuffer) {
			return elements << SIZEOF_SHORT;
		} else if (dst instanceof DoubleBuffer) {
			return elements << 3;
		} else { 
			throw new RuntimeException("Can't copy to a "
					+ dst.getClass().getName() + " instance");
		} 
	} 
 
	private static void putBuffer(Buffer dst, Object src, int offset,
			int numFloats) {