private final java.nio.ByteBuffer copyToByteBuffer(java.nio.Buffer buf) { if (buf instanceof java.nio.ByteBuffer) { if (buf.position() == 0) { return (java.nio.ByteBuffer) buf; } return Buffers.copyByteBuffer((java.nio.ByteBuffer) buf); } else if (buf instanceof java.nio.ShortBuffer) { return Buffers.copyShortBufferAsByteBuffer((java.nio.ShortBuffer) buf); } else if (buf instanceof java.nio.IntBuffer) { return Buffers.copyIntBufferAsByteBuffer((java.nio.IntBuffer) buf); } else if (buf instanceof java.nio.FloatBuffer) { return Buffers.copyFloatBufferAsByteBuffer((java.nio.FloatBuffer) buf); } else { throw new IllegalArgumentException( "Unsupported buffer type (must be one of byte, short, int, or float)"); } }