/** * Get a ByteBuffer mapped to a portion of this memory. * We keep a weak reference to all ByteBuffers provided so that this * memory object is not GC'd while there are still implicit outstanding * references to it (it'd be nice if we could attach our own reference to * the ByteBuffer, but the VM generates the object so we have no control * over it). * * @param offset byte offset from pointer to start the buffer * @param length Length of ByteBuffer * @return a direct ByteBuffer that accesses the memory being pointed to, */ @Override public ByteBuffer getByteBuffer(long offset, long length) { boundsCheck(offset, length); ByteBuffer b = super.getByteBuffer(offset, length); // Ensure this Memory object will not be GC'd (and its memory freed) // if the Buffer is still extant. buffers.put(b, this); return b; }
public ByteBuffer getNativeByteBuffer() { if (byteBuffer != null) { return byteBuffer; } byteBuffer = pointer.getByteBuffer(0, size); return byteBuffer; }
private void memcpyViaByteBuffer(Pointer dest, Pointer src, int byteCount) { ByteBuffer destBuffer = dest.getByteBuffer(0, byteCount); ByteBuffer srcBuffer = src.getByteBuffer(0, byteCount); destBuffer.put(srcBuffer); } }
/** * Get a ByteBuffer mapped to a portion of this memory. * * @param offset byte offset from pointer to start the buffer * @param length Length of ByteBuffer * @return a direct ByteBuffer that accesses the memory being pointed to, */ public ByteBuffer getByteBuffer(long offset, long length) { boundsCheck(offset, length); return super.getByteBuffer(offset, length); }
public ByteBuffer toByteBuffer() { ByteBuffer buffer = new Pointer(peer).getByteBuffer(0, size); if (buffer != null) return buffer; buffer = ByteBuffer.allocate((int) size); for (int i = 0; i < size; i++) buffer.put(getByteUnsafe(i)); buffer.flip(); return buffer; } }
@FuseMethod final int _readlink(final String path, final Pointer buffer, final TypeSize size) { final long bufSize = size.longValue(); final ByteBuffer buf = buffer.getByteBuffer(0, bufSize); final int result = readlink(path, buf, bufSize); if (result == 0) { try { buf.put((byte) 0); } catch (final BufferOverflowException e) { ((ByteBuffer) buf.position(buf.limit() - 1)).put((byte) 0); } } return result; }
/** * Gets a {@link java.nio.ByteBuffer} that can access the native memory * associated with this Buffer. * * @return A {@link java.nio.ByteBuffer} that can access this Buffer's data. */ public ByteBuffer map(boolean writeable) { final boolean ok = GSTBUFFER_API.gst_buffer_map(this, mapInfo, writeable ? GstBufferAPI.GST_MAP_WRITE : GstBufferAPI.GST_MAP_READ); if (ok && mapInfo.data != null) { return mapInfo.data.getByteBuffer(0, mapInfo.size.intValue()); } return null; }
/** * Gets a {@link java.nio.ByteBuffer} that can access the native memory * associated with this Buffer. * * @return A {@link java.nio.ByteBuffer} that can access this Buffer's data. */ public synchronized ByteBuffer getByteBuffer() { if (byteBuffer == null) { int size = getSize(); Pointer data = (Pointer) struct.readField("data"); if (data != null && size > 0) { byteBuffer = data.getByteBuffer(0, size); } } return byteBuffer; }
public static ByteBuf allocateAligned(int alignment, int size) { if (!JNA_AVAILABLE) throw new UnsupportedOperationException(); PointerByReference ptr = new PointerByReference(); int res = posix_memalign(ptr, new NativeLong(alignment), new NativeLong(size)); if (res < 0) return null; ByteBuffer allocation = ptr.getValue().getByteBuffer(0, size); // writerIndex(0) is required because ByteBuf when wraps native buffers // for some reason sets writer index to be capacity(). return Unpooled.wrappedBuffer(allocation).writerIndex(0); }
LOG.log(Level.FINEST, "Creating new audio port buffer"); int nbyteframes = nframes * FRAME_SIZE; port.byteBuffer = ptr.getByteBuffer(0, nbyteframes); port.floatBuffer = port.byteBuffer.asFloatBuffer(); } else if (port.type.equals(JackPortType.MIDI)) { LOG.log(Level.FINEST, "Creating new MIDI port buffer"); port.byteBuffer = ptr.getByteBuffer(0, 0); port.floatBuffer = port.byteBuffer.asFloatBuffer(); } else { LOG.log(Level.FINEST, "Creating new custom port buffer"); port.byteBuffer = ptr.getByteBuffer(0, port.type.getBufferSize()); port.floatBuffer = port.byteBuffer.asFloatBuffer();
/** * Get a ByteBuffer mapped to a portion of this memory. * We keep a weak reference to all ByteBuffers provided so that this * memory object is not GC'd while there are still implicit outstanding * references to it (it'd be nice if we could attach our own reference to * the ByteBuffer, but the VM generates the object so we have no control * over it). * * @param offset byte offset from pointer to start the buffer * @param length Length of ByteBuffer * @return a direct ByteBuffer that accesses the memory being pointed to, */ @Override public ByteBuffer getByteBuffer(long offset, long length) { boundsCheck(offset, length); ByteBuffer b = super.getByteBuffer(offset, length); // Ensure this Memory object will not be GC'd (and its memory freed) // if the Buffer is still extant. buffers.put(b, this); return b; }
@FuseMethod final int _setxattr(final String path, final String xattr, final Pointer value, final TypeSize size, final int flags, final int position) { final long sizeValue = size.longValue(); final ByteBuffer val = value.getByteBuffer(0, sizeValue); return setxattr(path, xattr, val, sizeValue, flags, position); }
@FuseMethod final int _listxattr(final String path, final Pointer buffer, final TypeSize size) { final long sizeValue = size.longValue(); final XattrListFiller filler = new XattrListFiller(buffer == null ? null : buffer.getByteBuffer(0, sizeValue), sizeValue); final int result = listxattr(path, filler); return result < 0 ? result : (int) filler.requiredSize(); }
content = new Pointer(pointer).getByteBuffer(0, contentSize); getByteBuffer(0, maxCompressedLength + 5).order(ByteOrder.nativeOrder());
@FuseMethod final int _write(final String path, final Pointer buffer, final TypeSize size, final TypeOff offset, final StructFuseFileInfo info) { final long bufSize = size.longValue(); final long writeOffset = offset.longValue(); final ByteBuffer buf = buffer.getByteBuffer(0, bufSize); final FileInfoWrapper wrapper = new FileInfoWrapper(path, info); final int result = write(path, buf, bufSize, writeOffset, wrapper); wrapper.write(); return result; }
@Override public void write(final List<ByteBuf> buffers) { byte[] message = createCompleteMessage(buffers); PointerByReference outputBufferReference = new PointerByReference(); IntByReference outputSize = new IntByReference(); MongoDBCAPIHelper.client_invoke(clientPointer, message, outputBufferReference, outputSize, clientStatusPointer); curResponse = outputBufferReference.getValue().getByteBuffer(0, outputSize.getValue()); }
@FuseMethod final int _read(final String path, final Pointer buffer, final TypeSize size, final TypeOff offset, final StructFuseFileInfo info) { final long bufSize = size.longValue(); final long readOffset = offset.longValue(); final ByteBuffer buf = buffer.getByteBuffer(0, bufSize); final FileInfoWrapper wrapper = new FileInfoWrapper(path, info); final int result = read(path, buf, bufSize, readOffset, wrapper); wrapper.write(); return result; }
@FuseMethod final int _getxattr(final String path, final String xattr, final Pointer buffer, final TypeSize size, final TypeUInt32 position) { final long sizeValue = size.longValue(); final int positionValue = position == null ? 0 : position.intValue(); final XattrFiller filler = new XattrFiller(buffer == null ? null : buffer.getByteBuffer(0, sizeValue), sizeValue, positionValue); final int result = getxattr(path, xattr, filler, sizeValue, position == null ? 0L : position.longValue()); return result < 0 ? result : (int) filler.getSize(); }