nread = 0; } else if (nread > 0) { buf.put(0, dest, 0, nread);
@Override protected final void in(final byte[] buffer, final Pointer ptr, final long ptrAddr) { final Pointer pointer = MEM_MGR.allocateDirect(buffer.length); pointer.put(0, buffer, 0, buffer.length); ptr.putLong(STRUCT_FIELD_OFFSET_SIZE, buffer.length); ptr.putLong(STRUCT_FIELD_OFFSET_DATA, pointer.address()); }
@Override protected final void in(final byte[] buffer, final Pointer ptr, final long ptrAddr) { final Pointer pointer = MEM_MGR.allocateDirect(buffer.length); pointer.put(0, buffer, 0, buffer.length); ptr.putLong(STRUCT_FIELD_OFFSET_SIZE, buffer.length); ptr.putAddress(STRUCT_FIELD_OFFSET_DATA, pointer.address()); }
void put(int idx, CharSequence str) { if (str == null) { memory.putAddress(idx * getRuntime().addressSize(), 0L); } else { ByteBuffer buf = charset.encode(CharBuffer.wrap(str)); Pointer ptr = Memory.allocateDirect(getRuntime(), buf.remaining() + 4, true); ptr.put(0, buf.array(), 0, buf.remaining()); stringMemory.add(idx, ptr); memory.putPointer(idx * getRuntime().addressSize(), ptr); } }
private int read(Pointer buffer, long size, long offset) { int bytesToRead = (int) Math.min(contents.capacity() - offset, size); byte[] bytesRead = new byte[bytesToRead]; synchronized (this) { contents.position((int) offset); contents.get(bytesRead, 0, bytesToRead); buffer.put(0, bytesRead, 0, bytesToRead); contents.position(0); // Rewind } return bytesToRead; }
@Override public void put(long offset, byte[] dst, int off, int len) { checkBounds(size, offset, len); io.put(base + offset, dst, off, len); }
@Override public void put(long offset, long[] src, int off, int len) { checkBounds(size, offset, len * Long.SIZE / 8); io.put(base + offset, src, off, len); }
@Override public void put(long offset, byte[] dst, int off, int len) { checkBounds(size, offset, len); io.put(base + offset, dst, off, len); }
@Override public void put(long offset, short[] dst, int off, int len) { checkBounds(size, offset, len * Short.SIZE / 8); io.put(base + offset, dst, off, len); }
@Override public void put(long offset, int[] src, int off, int len) { checkBounds(size, offset, len * Integer.SIZE / 8); io.put(base + offset, src, off, len); }
@Override public void put(long offset, short[] dst, int off, int len) { checkBounds(size, offset, len * Short.SIZE / 8); io.put(base + offset, dst, off, len); }
@Override public void put(long offset, long[] src, int off, int len) { checkBounds(size, offset, len * Long.SIZE / 8); io.put(base + offset, src, off, len); }
@Override public void put(long offset, double[] src, int off, int len) { checkBounds(size, offset, len * Double.SIZE / 8); io.put(base + offset, src, off, len); }
@Override public void put(long offset, long[] src, int off, int len) { checkBounds(size, offset, len * Long.SIZE / 8); io.put(base + offset, src, off, len); }
@Override public void put(long offset, double[] src, int off, int len) { checkBounds(size, offset, len * Double.SIZE / 8); io.put(base + offset, src, off, len); }
@Override public void put(long offset, byte[] dst, int off, int len) { checkBounds(size, offset, len); io.put(base + offset, dst, off, len); }
public Pointer toNative(WString value, ToNativeContext context) { if (value == null) { return null; } Pointer memory = Memory.allocateDirect(runtime, value.bytes.length + 1, true); memory.put(0, value.bytes, 0, value.bytes.length); return memory; }
public void setData(ByteBuffer data) { byte[] bytes = new byte[data.capacity() - data.position()]; data.get(bytes); posix.socketMacros().CMSG_DATA(this.memory).put(0, bytes, 0, bytes.length); }
public void setData(ByteBuffer data) { byte[] bytes = new byte[data.capacity() - data.position()]; data.get(bytes); posix.socketMacros().CMSG_DATA(this.memory).put(0, bytes, 0, bytes.length); }
public void setName(String name) { if (name == null) { setNamePointer(null); setNameLen(0); return; } byte[] nameBytes = name.getBytes(Charset.forName("US-ASCII")); Pointer p = Runtime.getSystemRuntime().getMemoryManager().allocateTemporary(nameBytes.length, true); p.put(0, nameBytes, 0, nameBytes.length); setNamePointer(p); setNameLen(nameBytes.length); }