/** * Copies {@code count} bytes from the memory pointed to by this * {@link BytePtr} to {@code dst} starting at offset {@code offset}. * * @param dst the destination. * @param offset the offset within the destination array to start copying to. * @param count the number of elements to copy. */ public void get(byte[] dst, int offset, int count) { asByteBuffer(count).get(dst, offset, count); }
/** * Copies {@code count} bytes from {@code src} starting at offset {@code offset} * to the memory pointed to by this {@link BytePtr}. * * @param src the source. * @param offset the offset within the source array to start copying from. * @param count the number of elements to copy. */ public void set(byte[] src, int offset, int count) { asByteBuffer(count).put(src, offset, count); }
/** * Returns a {@link DoubleBuffer} which reads and writes to the same memory * location pointed to by this {@link DoublePtr}. * * @param n the maximum number of doubles the {@link DoubleBuffer} can * read/write. This will be the {@link DoubleBuffer}'s * <code>capacity</code>. * @return the {@link DoubleBuffer}. */ public DoubleBuffer asDoubleBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 3).order(ByteOrder.nativeOrder()).asDoubleBuffer(); }
/** * Returns a {@link ShortBuffer} which reads and writes to the same memory * location pointed to by this {@link ShortPtr}. * * @param n the maximum number of shorts the {@link ShortBuffer} can * read/write. This will be the {@link ShortBuffer}'s * <code>capacity</code>. * @return the {@link ShortBuffer}. */ public ShortBuffer asShortBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 1).order(ByteOrder.nativeOrder()).asShortBuffer(); }
/** * Returns a {@link LongBuffer} which reads and writes to the same memory * location pointed to by this {@link LongPtr}. * * @param n the maximum number of longs the {@link LongBuffer} can * read/write. This will be the {@link LongBuffer}'s * <code>capacity</code>. * @return the {@link LongBuffer}. */ public LongBuffer asLongBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 3).order(ByteOrder.nativeOrder()).asLongBuffer(); }
/** * Returns a {@link IntBuffer} which reads and writes to the same memory * location pointed to by this {@link IntPtr}. * * @param n the maximum number of ints the {@link IntBuffer} can * read/write. This will be the {@link IntBuffer}'s * <code>capacity</code>. * @return the {@link IntBuffer}. */ public IntBuffer asIntBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 2).order(ByteOrder.nativeOrder()).asIntBuffer(); }
/** * Returns a {@link FloatBuffer} which reads and writes to the same memory * location pointed to by this {@link FloatPtr}. * * @param n the maximum number of floats the {@link FloatBuffer} can * read/write. This will be the {@link FloatBuffer}'s * <code>capacity</code>. * @return the {@link FloatBuffer}. */ public FloatBuffer asFloatBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); }
/** * Returns a {@link CharBuffer} which reads and writes to the same memory * location pointed to by this {@link CharPtr}. * * @param n the maximum number of chars the {@link CharBuffer} can * read/write. This will be the {@link CharBuffer}'s * <code>capacity</code>. * @return the {@link ShortBuffer}. */ public CharBuffer asCharBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 1).order(ByteOrder.nativeOrder()).asCharBuffer(); }
/** * Returns a {@link String} created from the NUL-terminated C string pointed * to by this {@link BytePtr} using the specified {@link Charset}. Illegal * characters will be replaced with '?' in the result. * * @param charset the {@link Charset} to use. Must be an 8-bit or variable * length character encoding with 8-bits as smallest value and that * can be NUL-terminated (e.g. UTF-8). * @return a {@link String} converted from the C string bytes. */ public String toStringZ(Charset charset) { int length = 0; long address = getHandle(); while (VM.getByte(address++) != 0) { length++; } return charset.decode(asByteBuffer(length)).toString(); }
public ByteBuffer getDataAsByteBuffer() { return getData0().asByteBuffer(getLength0()); } public MIDIRawData setData(byte[] data) {
public ByteBuffer getDataAsByteBuffer() { return getData0().asByteBuffer(getDataLength0()); } public MIDIMetaEvent setData(byte[] data) {
public ByteBuffer getDataAsByteBuffer() { return getData0().asByteBuffer(getLength0()); } public MusicEventUserData setData(byte[] data) {
@SuppressWarnings("unchecked") public <T extends Buffer> T getOutputDataAsBuffer(Class<T> bufferType) { VoidPtr ptr = getOutputDataPointer(); if (bufferType == ByteBuffer.class) { return (T) ptr.as(BytePtr.class).asByteBuffer(getOutputDataSize()); } else if (bufferType == CharBuffer.class) { return (T) ptr.as(CharPtr.class).asCharBuffer(getOutputDataSize()); } else if (bufferType == ShortBuffer.class) { return (T) ptr.as(ShortPtr.class).asShortBuffer(getOutputDataSize()); } else if (bufferType == IntBuffer.class) { return (T) ptr.as(IntPtr.class).asIntBuffer(getOutputDataSize()); } else if (bufferType == LongBuffer.class) { return (T) ptr.as(LongPtr.class).asLongBuffer(getOutputDataSize()); } else if (bufferType == FloatBuffer.class) { return (T) ptr.as(FloatPtr.class).asFloatBuffer(getOutputDataSize()); } else if (bufferType == DoubleBuffer.class) { return (T) ptr.as(DoublePtr.class).asDoubleBuffer(getOutputDataSize()); } else { throw new UnsupportedOperationException("Buffer type not supported: " + bufferType); } }
/** * Copies {@code count} bytes from {@code src} starting at offset {@code offset} * to the memory pointed to by this {@link BytePtr}. * * @param src the source. * @param offset the offset within the source array to start copying from. * @param count the number of elements to copy. */ public void set(byte[] src, int offset, int count) { asByteBuffer(count).put(src, offset, count); }
/** * Copies {@code count} bytes from the memory pointed to by this * {@link BytePtr} to {@code dst} starting at offset {@code offset}. * * @param dst the destination. * @param offset the offset within the destination array to start copying to. * @param count the number of elements to copy. */ public void get(byte[] dst, int offset, int count) { asByteBuffer(count).get(dst, offset, count); }
/** * Returns a {@link FloatBuffer} which reads and writes to the same memory * location pointed to by this {@link FloatPtr}. * * @param n the maximum number of floats the {@link FloatBuffer} can * read/write. This will be the {@link FloatBuffer}'s * <code>capacity</code>. * @return the {@link FloatBuffer}. */ public FloatBuffer asFloatBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); }
/** * Returns a {@link ShortBuffer} which reads and writes to the same memory * location pointed to by this {@link ShortPtr}. * * @param n the maximum number of shorts the {@link ShortBuffer} can * read/write. This will be the {@link ShortBuffer}'s * <code>capacity</code>. * @return the {@link ShortBuffer}. */ public ShortBuffer asShortBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 1).order(ByteOrder.nativeOrder()).asShortBuffer(); }
/** * Returns a {@link DoubleBuffer} which reads and writes to the same memory * location pointed to by this {@link DoublePtr}. * * @param n the maximum number of doubles the {@link DoubleBuffer} can * read/write. This will be the {@link DoubleBuffer}'s * <code>capacity</code>. * @return the {@link DoubleBuffer}. */ public DoubleBuffer asDoubleBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 3).order(ByteOrder.nativeOrder()).asDoubleBuffer(); }
/** * Returns a {@link IntBuffer} which reads and writes to the same memory * location pointed to by this {@link IntPtr}. * * @param n the maximum number of ints the {@link IntBuffer} can * read/write. This will be the {@link IntBuffer}'s * <code>capacity</code>. * @return the {@link IntBuffer}. */ public IntBuffer asIntBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 2).order(ByteOrder.nativeOrder()).asIntBuffer(); }
/** * Returns a {@link CharBuffer} which reads and writes to the same memory * location pointed to by this {@link CharPtr}. * * @param n the maximum number of chars the {@link CharBuffer} can * read/write. This will be the {@link CharBuffer}'s * <code>capacity</code>. * @return the {@link ShortBuffer}. */ public CharBuffer asCharBuffer(int n) { return as(BytePtr.class).asByteBuffer(n << 1).order(ByteOrder.nativeOrder()).asCharBuffer(); }