public static void readInDirectBuffer()

in hadoop-api-shim/src/main/java/org/apache/hadoop/fs/shim/impl/VectoredRangeReadImpl.java [90:110]


  public static void readInDirectBuffer(int length,
      ByteBuffer buffer,
      Function4RaisingIOE<Integer, byte[], Integer, Integer, Void> operation)
      throws IOException {
    if (length == 0) {
      return;
    }
    int readBytes = 0;
    int position = 0;
    int tmpBufferMaxSize = Math.min(TMP_BUFFER_MAX_SIZE, length);
    byte[] tmp = new byte[tmpBufferMaxSize];
    while (readBytes < length) {
      int currentLength = (readBytes + tmpBufferMaxSize) < length
          ? tmpBufferMaxSize
          : (length - readBytes);
      operation.apply(position, tmp, 0, currentLength);
      buffer.put(tmp, 0, currentLength);
      position = position + currentLength;
      readBytes = readBytes + currentLength;
    }
  }