@Override public void putBytes(final long l, final byte[] bytes) { putBytes(l, bytes, 0, bytes.length); }
@Override public void putBytes(long l, Memory source) { putBytes(l, source, 0, source.length()); }
public void putBytes(long l, DirectMemory source) { putBytes(l, source, 0, source.length()); }
@Override public void putBytes(long l, ByteBuffer source) { final int length = source.remaining(); checkBounds(l, length); if (source.isDirect()) { NativeMemoryUtils.copyFromDirectBuffer(source, source.position(), address+l, length); source.position(source.position()+length); } else if (source.hasArray()) { final byte[] array = source.array(); final int offset = source.arrayOffset(); putBytes(l, array, offset+source.position(), length); source.position(source.position()+length); } else { final byte[] copyBuffer = new byte[Math.min(length, 4096)]; long destAddr = l; while (source.remaining() > 0) { final int copySize = Math.min(copyBuffer.length, source.remaining()); source.get(copyBuffer, 0, copySize); putBytes(destAddr, copyBuffer, 0, copySize); destAddr+=copySize; } } }
@Override public void putBytes(long l, Memory source, long start, long length) { if (source.isDirect()) { putBytes(l, (DirectMemory) source, start, length); } else { source.getBytes(start, this, l, length); } }
private NativeBuffer createNewAndClose(long newSize) { final NativeBuffer ret = new NativeBuffer(newSize, memory.getOrder()); ret.memory().putBytes(0, memory, 0, Math.min(memory.length(), newSize)); closeQuietly(this); return ret; }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { if (off < 0 || len < 0 || off+len > b.length) { throw new IndexOutOfBoundsException(); } if (currentAddress + len > memory.length()) { buffer = buffer.realloc(memory.length()*2); memory = buffer.memory(); write(b, off, len); } else { memory.putBytes(currentAddress, b, off, len); currentAddress+=len; } }