public ByteDataBuffer copyTo()

in ndarray/src/main/java/org/tensorflow/ndarray/impl/buffer/raw/ByteRawDataBuffer.java [69:103]


  public ByteDataBuffer copyTo(DataBuffer<Byte> dst, long size) {
    Validator.copyToArgs(this, dst, size);
    return dst.accept(new DataStorageVisitor<ByteDataBuffer>() {

      @Override
      public ByteDataBuffer visit(ByteBuffer buffer) {
        if (buffer.hasArray()) {
          memory.copyTo(UnsafeMemoryHandle.fromArray(buffer.array(), buffer.position(), buffer.limit()), size);
        } else if (memory.isArray()) {
          buffer.put(memory.toArrayByteBuffer());
        } else {
          slowCopyTo(dst, size);
        }
        return ByteRawDataBuffer.this;
      }

      @Override
      public ByteDataBuffer visit(long address, long length, long scale) {
        memory.copyTo(UnsafeMemoryHandle.fromAddress(address, length, scale), size);
        return ByteRawDataBuffer.this;
      }

      @Override
      public ByteDataBuffer fallback() {
        if (dst instanceof ByteDataBuffer) {
          ByteDataBuffer byteDst = (ByteDataBuffer)dst;
          for (long idx = 0L; idx < size; ++idx) {
            byteDst.setByte(getByte(idx), idx);
          }
          return ByteRawDataBuffer.this;
        }
        return slowCopyTo(dst, size);
      }
    });
  }