Ejemplo n.º 1
0
  /**
   * Meant for creating another view of a buffer
   *
   * @param underlyingBuffer the underlying buffer to create a view from
   * @param length the length of the view
   * @param offset the offset for the view
   */
  protected BaseDataBuffer(DataBuffer underlyingBuffer, int length, int offset) {
    this.length = length;
    this.offset = offset;
    this.allocationMode = underlyingBuffer.allocationMode();
    this.elementSize = underlyingBuffer.getElementSize();
    this.underlyingLength = underlyingBuffer.underlyingLength() - offset;
    this.wrappedDataBuffer = underlyingBuffer;

    if (underlyingBuffer.dataType() == Type.DOUBLE) {
      if (underlyingBuffer.allocationMode() == AllocationMode.HEAP) {
        double[] underlyingArray = (double[]) underlyingBuffer.array();
        this.doubleData = underlyingArray;
      } else {
        ByteBuffer underlyingBuff = underlyingBuffer.asNio();
        this.wrappedBuffer = underlyingBuff;
      }
    } else if (underlyingBuffer.dataType() == Type.FLOAT) {
      if (underlyingBuffer.allocationMode() == AllocationMode.HEAP) {
        float[] underlyingArray = (float[]) underlyingBuffer.array();
        this.floatData = underlyingArray;
      } else {
        ByteBuffer underlyingBuff = underlyingBuffer.asNio();
        this.wrappedBuffer = underlyingBuff;
      }
    } else if (underlyingBuffer.dataType() == Type.INT) {
      if (underlyingBuffer.allocationMode() == AllocationMode.HEAP) {
        int[] underlyingArray = (int[]) underlyingBuffer.array();
        this.intData = underlyingArray;
      } else {
        ByteBuffer underlyingBuff = underlyingBuffer.asNio();
        this.wrappedBuffer = underlyingBuff;
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Meant for creating another view of a buffer
   *
   * @param underlyingBuffer the underlying buffer to create a view from
   * @param length the length of the view
   * @param offset the offset for the view
   */
  protected BaseDataBuffer(DataBuffer underlyingBuffer, long length, long offset) {
    if (length < 1) throw new IllegalArgumentException("Length must be >= 1");
    initTypeAndSize();
    this.length = length;
    this.offset = offset;
    this.allocationMode = underlyingBuffer.allocationMode();
    this.elementSize = underlyingBuffer.getElementSize();
    this.underlyingLength = underlyingBuffer.underlyingLength();
    this.wrappedDataBuffer = underlyingBuffer;

    // Adding link to original databuffer
    if (underlyingBuffer.originalDataBuffer() == null) {
      this.originalBuffer = underlyingBuffer;
      this.originalOffset = offset;
    } else {

      this.originalBuffer = underlyingBuffer.originalDataBuffer();

      // FIXME: please don't remove this comment, since there's probably a bug in current offset()
      // impl,
      // and this line will change originalOffset accroding to proper offset() impl
      // FIXME: [email protected]
      this.originalOffset = offset; // + underlyingBuffer.originalOffset();
    }

    if (underlyingBuffer.dataType() == Type.DOUBLE) {
      pointer = underlyingBuffer.pointer();
      indexer = underlyingBuffer.indexer();
    } else if (underlyingBuffer.dataType() == Type.FLOAT) {
      pointer = underlyingBuffer.pointer();
      indexer = underlyingBuffer.indexer();
    } else if (underlyingBuffer.dataType() == Type.INT) {
      pointer = underlyingBuffer.pointer();
      indexer = underlyingBuffer.indexer();
    }
  }