public static final boolean isDirect(Buffer buffer) {
        if (buffer == null) {
            return true;
        }
        
        if (!(buffer instanceof ByteBuffer)) {
            if (buffer instanceof FloatBuffer) {
                return ((FloatBuffer) buffer).isDirect();
            }
            if (buffer instanceof DoubleBuffer) {
                return ((DoubleBuffer) buffer).isDirect();
            }
            if (!(buffer instanceof CharBuffer)) {
                if (buffer instanceof ShortBuffer) {
                    return ((ShortBuffer) buffer).isDirect();
                }
                if (!(buffer instanceof IntBuffer)) {
                    if (buffer instanceof LongBuffer) {
                        return ((LongBuffer) buffer).isDirect();
                    } else {
                        throw new InvalidParameterException("Buffer " + buffer.getClass() + " is invalid");
                    }
                } else {
                    return ((IntBuffer) buffer).isDirect();
                }
            } else {
                return ((CharBuffer) buffer).isDirect();
            }
        } else {
            return ((ByteBuffer) buffer).isDirect();
        }
    }