Code example for FloatBuffer

Methods: limit, position, put

0
			writer.limit(numFloats);
			writer.put(buffer, offset, numFloats);
		} else if (dst instanceof FloatBuffer) {
			float[] buffer = (float[]) src;
			FloatBuffer writer = (FloatBuffer) dst;
			writer.limit(numFloats);
			writer.put(buffer, offset, numFloats);
		} else if (dst instanceof DoubleBuffer) {
			double[] buffer = (double[]) src;
			DoubleBuffer writer = (DoubleBuffer) dst;
			writer.limit(numFloats);
			writer.put(buffer, offset, numFloats);
		} else { 
			throw new RuntimeException("Can't copy to a "
					+ dst.getClass().getName() + " instance");
		} 
		dst.position(0);
	} 
 
	private static void putBuffer(Buffer dst, Buffer src, int numFloats) {
		if (dst instanceof ByteBuffer) {
			ByteBuffer buffer = (ByteBuffer) dst;
			buffer.limit(numFloats);
			buffer.put((ByteBuffer) src);
		} else if (dst instanceof ShortBuffer) {
			ShortBuffer buffer = (ShortBuffer) dst;
			buffer.limit(numFloats);
			buffer.put((ShortBuffer) src);
		} else if (dst instanceof CharBuffer) {
			CharBuffer buffer = (CharBuffer) dst;
			buffer.limit(numFloats);
			buffer.put((CharBuffer) src);
		} else if (dst instanceof IntBuffer) {
			IntBuffer buffer = (IntBuffer) dst;
			buffer.limit(numFloats);
			buffer.put((IntBuffer) src);
		} else if (dst instanceof LongBuffer) {
			LongBuffer buffer = (LongBuffer) dst;
			buffer.limit(numFloats);
			buffer.put((LongBuffer) src);
		} else if (dst instanceof FloatBuffer) {
			FloatBuffer buffer = (FloatBuffer) dst;
			buffer.limit(numFloats);
			buffer.put((FloatBuffer) src);
		} else if (dst instanceof DoubleBuffer) {
			DoubleBuffer buffer = (DoubleBuffer) dst;
			buffer.limit(numFloats);
			buffer.put((DoubleBuffer) src);
		} else { 
			throw new RuntimeException("Can't copy to a "
					+ dst.getClass().getName() + " instance");
		} 
		dst.position(0);
	} 
 
	public static ByteBuffer replaceBytes(ByteBuffer dst, float[] src) {
		int size = src.length;
		dst.clear();
		copy(src, 0, dst, size);
		dst.position(0);
		return dst;
	} 
 
	public static FloatBuffer replaceFloats(FloatBuffer dst, float[] src) {
		int size = src.length;
		dst.clear();
		copy(src, 0, dst, size);
		dst.position(0);
		return dst;
	} 
 
	public static ByteBuffer getByteBuffer(byte[] bytes) {
		if (useLoonNative) {
			final int size = bytes.length;
			ByteBuffer buffer = newByteBuffer(size);
			copy(bytes, 0, buffer, size);
			buffer.position(0);
			return buffer;
		} else { 
			ByteBuffer buffer = newByteBuffer(bytes.length).put(bytes);
			buffer.position(0);
			return buffer;
		} 
	} 
 
	public static FloatBuffer getFloatBuffer(float[] floats) {
		if (useLoonNative) {
			final int size = floats.length;
			FloatBuffer buffer = newFloatBuffer(size);
			copy(floats, 0, buffer, size);
			buffer.position(0);
			return buffer;
		} else { 
			FloatBuffer buffer = newFloatBuffer(floats.length).put(floats);
			buffer.position(0);
			return buffer;