Java Code Examples for io.netty.util.internal.PlatformDependent#copyMemory()

The following examples show how to use io.netty.util.internal.PlatformDependent#copyMemory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrillBuf.java    From Bats with Apache License 2.0 6 votes vote down vote up
public ByteBuf setBytes(int index, ByteBuffer src, int srcIndex, int length) {
  if (src.isDirect()) {
    checkIndex(index, length);
    PlatformDependent.copyMemory(PlatformDependent.directBufferAddress(src) + srcIndex, this.memoryAddress() + index,
        length);
  } else {
    if (srcIndex == 0 && src.capacity() == length) {
      udle.setBytes(index + offset, src);
    } else {
      ByteBuffer newBuf = src.duplicate();
      newBuf.position(srcIndex);
      newBuf.limit(srcIndex + length);
      udle.setBytes(index + offset, src);
    }
  }

  return this;
}
 
Example 2
Source File: PooledUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@Override
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
    checkIndex(index, length);
    if (src == null) {
        throw new NullPointerException("src");
    }
    if (srcIndex < 0 || srcIndex > src.capacity() - length) {
        throw new IndexOutOfBoundsException("srcIndex: " + srcIndex);
    }

    if (length != 0) {
        if (src.hasMemoryAddress()) {
            PlatformDependent.copyMemory(src.memoryAddress() + srcIndex, addr(index), length);
        } else if (src.hasArray()) {
            PlatformDependent.copyMemory(src.array(), src.arrayOffset() + srcIndex, addr(index), length);
        } else {
            src.getBytes(srcIndex, this, index, length);
        }
    }
    return this;
}
 
Example 3
Source File: PoolArena.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
protected void memoryCopy(ByteBuffer src, int srcOffset, ByteBuffer dst, int dstOffset, int length) {
    if (length == 0) {
        return;
    }

    if (HAS_UNSAFE) {
        PlatformDependent.copyMemory(
                PlatformDependent.directBufferAddress(src) + srcOffset,
                PlatformDependent.directBufferAddress(dst) + dstOffset, length);
    } else {
        // We must duplicate the NIO buffers because they may be accessed by other Netty buffers.我们必须复制NIO缓冲区,因为它们可能被其他Netty缓冲区访问。
        src = src.duplicate();
        dst = dst.duplicate();
        src.position(srcOffset).limit(srcOffset + length);
        dst.position(dstOffset);
        dst.put(src);
    }
}
 
Example 4
Source File: ReadOnlyUnsafeDirectByteBuf.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
    checkIndex(index, length);
    if (dst == null) {
        throw new NullPointerException("dst");
    }
    if (dstIndex < 0 || dstIndex > dst.capacity() - length) {
        throw new IndexOutOfBoundsException("dstIndex: " + dstIndex);
    }

    if (dst.hasMemoryAddress()) {
        PlatformDependent.copyMemory(addr(index), dst.memoryAddress() + dstIndex, length);
    } else if (dst.hasArray()) {
        PlatformDependent.copyMemory(addr(index), dst.array(), dst.arrayOffset() + dstIndex, length);
    } else {
        dst.setBytes(dstIndex, this, index, length);
    }
    return this;
}
 
Example 5
Source File: UnpooledUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public int setBytes(int index, InputStream in, int length) throws IOException {
    checkIndex(index, length);
    byte[] tmp = new byte[length];
    int readBytes = in.read(tmp);
    if (readBytes > 0) {
        PlatformDependent.copyMemory(tmp, 0, addr(index), readBytes);
    }
    return readBytes;
}
 
Example 6
Source File: PooledUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
    checkIndex(index, length);
    if (dst == null) {
        throw new NullPointerException("dst");
    }
    if (dstIndex < 0 || dstIndex > dst.length - length) {
        throw new IndexOutOfBoundsException("dstIndex: " + dstIndex);
    }
    if (length != 0) {
        PlatformDependent.copyMemory(addr(index), dst, dstIndex, length);
    }
    return this;
}
 
Example 7
Source File: UnpooledHeapByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
    checkDstIndex(index, length, dstIndex, dst.capacity());
    if (dst.hasMemoryAddress()) {
        PlatformDependent.copyMemory(array, index, dst.memoryAddress() + dstIndex, length);
    } else if (dst.hasArray()) {
        getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length);
    } else {
        dst.setBytes(dstIndex, array, index, length);
    }
    return this;
}
 
Example 8
Source File: PooledHeapByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
    checkDstIndex(index, length, dstIndex, dst.capacity());
    if (dst.hasMemoryAddress()) {
        PlatformDependent.copyMemory(memory, idx(index), dst.memoryAddress() + dstIndex, length);
    } else if (dst.hasArray()) {
        getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length);
    } else {
        dst.setBytes(dstIndex, memory, idx(index), length);
    }
    return this;
}
 
Example 9
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void getBytes(AbstractByteBuf buf, long addr, int index, ByteBuf dst, int dstIndex, int length) {
    buf.checkIndex(index, length);
    checkNotNull(dst, "dst");
    if (isOutOfBounds(dstIndex, length, dst.capacity())) {
        throw new IndexOutOfBoundsException("dstIndex: " + dstIndex);
    }

    if (dst.hasMemoryAddress()) {
        PlatformDependent.copyMemory(addr, dst.memoryAddress() + dstIndex, length);
    } else if (dst.hasArray()) {
        PlatformDependent.copyMemory(addr, dst.array(), dst.arrayOffset() + dstIndex, length);
    } else {
        dst.setBytes(dstIndex, buf, index, length);
    }
}
 
Example 10
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static int setBytes(AbstractByteBuf buf, long addr, int index, InputStream in, int length) throws IOException {
    buf.checkIndex(index, length);
    ByteBuf tmpBuf = buf.alloc().heapBuffer(length);
    try {
        byte[] tmp = tmpBuf.array();
        int offset = tmpBuf.arrayOffset();
        int readBytes = in.read(tmp, offset, length);
        if (readBytes > 0) {
            PlatformDependent.copyMemory(tmp, offset, addr, readBytes);
        }
        return readBytes;
    } finally {
        tmpBuf.release();
    }
}
 
Example 11
Source File: UnSafeTuple.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] getBytes(int fieldId) {
  long pos = getFieldAddr(fieldId);
  int len = PlatformDependent.getInt(pos);
  pos += SizeOf.SIZE_OF_INT;

  byte [] bytes = new byte[len];
  PlatformDependent.copyMemory(pos, bytes, 0, len);
  return bytes;
}
 
Example 12
Source File: LBlockHashTableNoSpill.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public void traceOrdinals(final long indexes, final int numRecords) {
  if (traceBuf == null) {
    return;
  }
  PlatformDependent.copyMemory(indexes, traceBufNext, 4 * numRecords);
  traceBufNext += 4 * numRecords;
}
 
Example 13
Source File: UnSafeTuple.java    From tajo with Apache License 2.0 5 votes vote down vote up
public HeapTuple toHeapTuple() {
  HeapTuple heapTuple = new HeapTuple();
  byte [] bytes = new byte[getLength()];
  PlatformDependent.copyMemory(address(), bytes, 0, getLength());
  heapTuple.set(bytes, types);
  return heapTuple;
}
 
Example 14
Source File: PooledHeapByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public final ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
    checkSrcIndex(index, length, srcIndex, src.capacity());
    if (src.hasMemoryAddress()) {
        PlatformDependent.copyMemory(src.memoryAddress() + srcIndex, memory, idx(index), length);
    } else if (src.hasArray()) {
        setBytes(index, src.array(), src.arrayOffset() + srcIndex, length);
    } else {
        src.getBytes(srcIndex, memory, idx(index), length);
    }
    return this;
}
 
Example 15
Source File: PooledHeapByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public final ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
    checkDstIndex(index, length, dstIndex, dst.capacity());
    if (dst.hasMemoryAddress()) {
        PlatformDependent.copyMemory(memory, idx(index), dst.memoryAddress() + dstIndex, length);
    } else if (dst.hasArray()) {
        getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length);
    } else {
        dst.setBytes(dstIndex, memory, idx(index), length);
    }
    return this;
}
 
Example 16
Source File: UnsafeDirectLittleEndian.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException {
  wrapped.checkIndex(index, length);
  if (length != 0) {
    byte[] tmp = new byte[length];
    PlatformDependent.copyMemory(addr(index), tmp, 0, length);
    out.write(tmp);
  }
  return this;
}
 
Example 17
Source File: UnsafeDirectLittleEndian.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public int setBytes(int index, InputStream in, int length) throws IOException {
  wrapped.checkIndex(index, length);
  byte[] tmp = new byte[length];
  int readBytes = in.read(tmp);
  if (readBytes > 0) {
    PlatformDependent.copyMemory(tmp, 0, addr(index), readBytes);
  }
  return readBytes;
}
 
Example 18
Source File: PooledUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public int setBytes(int index, InputStream in, int length) throws IOException {
    checkIndex(index, length);
    byte[] tmp = new byte[length];
    int readBytes = in.read(tmp);
    if (readBytes > 0) {
        PlatformDependent.copyMemory(tmp, 0, addr(index), readBytes);
    }
    return readBytes;
}
 
Example 19
Source File: VariableBlockVector.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void resizeBuffer(int sizeInBytes) {
  int targetSize = Numbers.nextPowerOfTwo(sizeInBytes);
  final ArrowBuf oldBuf = buf;
  buf = allocator.buffer(targetSize);
  PlatformDependent.copyMemory(oldBuf.memoryAddress(), buf.memoryAddress(), oldBuf.capacity());
  buf.writerIndex(oldBuf.writerIndex());
  oldBuf.release();
}
 
Example 20
Source File: Copier.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static void unsafeCopy1MB(final long src, final long dst, int len) {
  PlatformDependent.copyMemory(src, dst, len);
}