Tries to read length bytes to dst.
@param dst
@param offset
@param length
@return
@throws IOException
@throws EOFException If get request couldn't be filled.
515064
public FilterByteBuffer get(byte[] dst, int offset, int length) throws IOException
    {
        checkIn();
        int len = length;
        int count = 100;
        while (len > 0 && count > 0)
        {
            int rc = in.read(dst, offset+length-len, len);
            if (rc == -1)
            {
                throw new EOFException();
            }
            len -= rc;
            count--;
        }
        if (count == 0)
        {
            throw new IOException("couldn't fill buffer after 100 tries");
        }
        position += length;
        return this;
    }
489924
public static final Bytes of(byte[] data, int offset, int length) {
    Objects.requireNonNull(data);
    if (length == 0) {
      return EMPTY;
    }
    byte[] copy = new byte[length];
    System.arraycopy(data, offset, copy, 0, length);
    return new Bytes(copy);
  }
1126123
@Override
  public int read(byte []buf, int offset, int length) throws IOException
  {
    try {
      SocketChannel s = _s;
      
      if (s == null) {
        return -1;
      }
      
      int remaining = _readBuffer.remaining();
      if (remaining <= 0) {
        _readBuffer.clear();
        
        if (s.read(_readBuffer) < 0) {
          _readBuffer.flip();
          return -1;
        }
        
        _readBuffer.flip();
        
        remaining = _readBuffer.remaining();
      }
      
      int sublen = Math.min(remaining, length); 

      _readBuffer.get(buf, offset, sublen);
      
      int readLength = sublen;

      if (readLength >= 0) {
        _totalReadBytes += readLength;
      }

      return readLength;
    } catch (InterruptedIOException e) {
      if (_throwReadInterrupts)
        throw e;
      
      log.log(Level.FINEST, e.toString(), e);
    } catch (IOException e) {
      if (_throwReadInterrupts) {
        throw e;
      }

      if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, e.toString(), e);
      }
      else {
        log.finer(e.toString());
      }
      // server/0611
      /*
      try {
        close();
      } catch (IOException e1) {
      }
      */
    }

    return -1;
  }
1345030
public int read(CharBuffer buf, int length) throws IOException
  {
    int len = buf.length();

    buf.length(len + length);
    
    int readLength = read(buf.buffer(), len, length);
    
    if (readLength < 0) {
      buf.length(len);
    }
    else if (readLength < length) {
      buf.length(len + readLength);
    }

    return length;
  }
515978
public synchronized int read(byte[] buf, int offset, int length) 
        throws IOException
    {

        if (!waitForContent())
            return -1;
            
         if (length>_buffer.remaining())
            length=_buffer.remaining();
            
         _buffer.get(buf, offset, length);
        return length;
    }
424140
public static byte[] readBytes(byte b[], int offset, int length) {
    byte[] retValue = new byte[length];
    System.arraycopy(b, offset, retValue, 0, length);
    return retValue;
  }
1115021
public static void readFully(InputStream in, byte[] dst, int offset, int byteCount) throws IOException {
        if (byteCount == 0) {
            return;
        }
        if (in == null) {
            throw new NullPointerException("in == null");
        }
        if (dst == null) {
            throw new NullPointerException("dst == null");
        }
        Arrays.checkOffsetAndCount(dst.length, offset, byteCount);
        while (byteCount > 0) {
            int bytesRead = in.read(dst, offset, byteCount);
            if (bytesRead < 0) {
                throw new EOFException();
            }
            offset += bytesRead;
            byteCount -= bytesRead;
        }
    }
1208175
public void readBytes (byte[] bytes, int offset, int count) throws KryoException {
		if (bytes == null) throw new IllegalArgumentException("bytes cannot be null.");
		int copyCount = Math.min(limit - position, count);
		while (true) {
			System.arraycopy(buffer, position, bytes, offset, copyCount);
			position += copyCount;
			count -= copyCount;
			if (count == 0) break;
			offset += copyCount;
			copyCount = Math.min(count, capacity);
			require(copyCount);
		}
	}
14051
public synchronized int get(byte[] dst, int off, int len) {
        if (available == 0) {
            return 0;
        }

        // limit is last index to read + 1
        int limit = idxGet < idxPut ? idxPut : capacity;
        int count = Math.min(limit - idxGet, len);
        System.arraycopy(buffer, idxGet, dst, off, count);
        idxGet += count;

        if (idxGet == capacity) {
            // Array end reached, check if we have more
            int count2 = Math.min(len - count, idxPut);
            if (count2 > 0) {
                System.arraycopy(buffer, 0, dst, off + count, count2);
                idxGet = count2;
                count += count2;
            } else {
                idxGet = 0;
            }
        }
        available -= count;
        return count;
    }
1044135
@Override
    public WsByteBuffer get(byte[] dst, int offset, int length) {
        convertBufferIfNeeded();
        return super.get(dst, offset, length);
    }
535328
@Override
    public int read(byte[] output, int offset, int length) throws IOException {
        synchronized(this){
            int value = 0;
            if(closed) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                    Tr.error(tc, "stream.is.closed.no.read.write");
                throw new IOException(Tr.formatMessage(tc, "stream.is.closed.no.read.write"));
            }
            if(output == null){
                if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                    Tr.error(tc, "read.write.bytearray.null");
                throw new NullPointerException(Tr.formatMessage(tc, "read.write.bytearray.null"));
            }
            if((offset < 0) || (length < 0) || (length > (output.length - offset))){
                if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                    Tr.error(tc, "read.write.offset.length.bytearraylength", new Object[] {offset, length, output.length});
                throw new IndexOutOfBoundsException(Tr.formatMessage(tc, "read.write.offset.length.bytearraylength", new Object[] {offset, length, output.length}));
            }

            if (this._inBuffer != null) {
                value = _inBuffer.read(output, offset, length);
            }
            else {
                value = this.in.read(output, offset, length);
            }

            return value;
        }
    }
388946
public static long bytes(byte[] data, int offset, int length) {
        CRC32 crc32 = new CRC32();
        crc32.update(data, offset, length);
        return crc32.getValue();
    }
1365255
public int readString(char[] buffer, int offset, int length)
        throws IOException
    {
        int readLength = 0;

        if (_chunkLength == END_OF_DATA) {
            _chunkLength = 0;
            return -1;
        }
        else if (_chunkLength == 0) {
            int tag = read();

            switch (tag) {
                case 'N':
                    return -1;

                case 'S':
                case 's':
                case 'X':
                case 'x':
                    _isLastChunk = tag == 'S' || tag == 'X';
                    _chunkLength = (read() << 8) + read();
                    break;

                default:
                    throw new IOException("expected 'S' at " + (char) tag);
            }
        }

        while (length > 0) {
            if (_chunkLength > 0) {
                buffer[offset++] = (char) parseUTF8Char();
                _chunkLength--;
                length--;
                readLength++;
            }
            else if (_isLastChunk) {
                if (readLength == 0)
                    return -1;
                else {
                    _chunkLength = END_OF_DATA;
                    return readLength;
                }
            }
            else {
                int tag = read();

                switch (tag) {
                    case 'S':
                    case 's':
                    case 'X':
                    case 'x':
                        _isLastChunk = tag == 'S' || tag == 'X';
                        _chunkLength = (read() << 8) + read();
                        break;

                    default:
                        throw new IOException("expected 'S' at " + (char) tag);
                }
            }
        }

        if (readLength == 0)
            return -1;
        else if (_chunkLength > 0 || !_isLastChunk)
            return readLength;
        else {
            _chunkLength = END_OF_DATA;
            return readLength;
        }
    }
966367
private static int appendByte(byte[] dst, int offset, long value) {
        if (value == 0) {
            return offset;
        }
        dst[offset] = (byte) value;
        return offset + 1;
    }
778232
@Override
  public synchronized int read(byte[] buf, int offset, int length) throws IOException {
    if (buf == null) {
      throw new IllegalArgumentException("buf must not be null");
    }

    if (!(offset >= 0 && length > 0 && offset < buf.length && length <= (buf.length - offset))) {
      throw new IllegalArgumentException("invalid offset and lengeth");
    }

    // Return early if closed is true; throw the saved exception if needed.
    if (closed) {
      if (exception != null) {
        throw exception;
      }
      return -1;
    }

    // Check if there is already a chunk that hasn't been exhausted; call take() if not.
    if (currentChunk == null) {
      if (currentChunkReadPos != -1) {
        throw new IllegalStateException("currentChunk is null but currentChunkReadPos is not -1");
      }

      byte[] next = null;
      try {
        if (timeoutMillis >= 0) {
          next = queue.poll(timeoutMillis, TimeUnit.MILLISECONDS);
        } else {
          next = queue.take();
        }
      } catch (InterruptedException e) {
        // Unlikely to happen.
        throw new AssertionError(e);
      }
      if (next == null) {
        closed = true;
        SocketTimeoutException timeoutException = new SocketTimeoutException();

        if (exception == null) {
          exception = timeoutException;
          // It is still possible that an endOffer(Exception) races and set exception at this point,
          // but timeoutException is still being thrown, and it's ok for subsequent reads to
          // throw the exception set by endOffer(Exception).
        }

        throw timeoutException;
      }

      // If it's the end marker, acknowledge that so that the buffer will mark itself as closed
      // for reading.
      if (next == CLOSED) {
        closed = true;
        if (exception != null) {
          throw exception;
        }
        return -1;
      }
      currentChunk = next;
      currentChunkReadPos = 0;
    }

    int available = currentChunk.length - currentChunkReadPos;
    if (length < available) {
      // Copy from the currentChunk.
      System.arraycopy(currentChunk, currentChunkReadPos, buf, offset, length);
      currentChunkReadPos += length;
      return length;
    } else {
      // Copy the entire currentChunk.
      System.arraycopy(currentChunk, currentChunkReadPos, buf, offset, available);
      currentChunk = null;
      currentChunkReadPos = -1;
      return available;
    }
  }
1219257
public int read(long position, byte[] buffer, int offset, int length,
      ReadOptions options)
    throws IOException {      
    // sanity checks
    dfsClient.checkOpen();
    if (closed) {
      throw new IOException("Stream closed");
    }
    DFSClient.dfsInputStreamfailures.set(0);
			long start = System.currentTimeMillis();
    long filelen = getFileLength();
    if ((position < 0) || (position >= filelen)) {
      return -1;
    }
    int realLen = length;
    if ((position + length) > filelen) {
      realLen = (int)(filelen - position);
    }
    
    DFSReadProfilingData pData = DFSClient.getDFSReadProfilingData();

    // determine the block and byte range within the block
    // corresponding to position and realLen
    List<LocatedBlock> blockRange = getBlockRange(position, realLen);
    
    if (!tryPreadFromLocal(blockRange, position, buffer, offset, length,
        realLen, start)) {
      // non-local or multiple block read.
      int remaining = realLen;
      for (LocatedBlock blk : blockRange) {
        long targetStart = position - blk.getStartOffset();
        long bytesToRead = Math.min(remaining, blk.getBlockSize() - targetStart);
        if (dfsClient.allowParallelReads && dfsClient.parallelReadsThreadPool != null) {
          fetchBlockByteRangeSpeculative(blk, targetStart,
                              targetStart + bytesToRead - 1, buffer, offset,
                              options);
        } else {
          if (pData != null) {
            cliData = new FSClientReadProfilingData();
            pData.addDFSClientReadProfilingData(cliData);
            cliData.startRead();
          }
          
          fetchBlockByteRange(blk, targetStart,
                              targetStart + bytesToRead - 1, buffer, offset,
                              options);
          
          if (pData != null) {
            cliData.endRead();
          }
        }
        remaining -= bytesToRead;
        position += bytesToRead;
        offset += bytesToRead;
      }
      assert remaining == 0 : "Wrong number of bytes read.";
    }
    
    if (dfsClient.stats != null) {
      dfsClient.stats.incrementBytesRead(realLen);
    }
    long timeval = System.currentTimeMillis() - start;
    dfsClient.metrics.incPreadTime(timeval);
    dfsClient.metrics.incPreadSize(realLen);
    dfsClient.metrics.incPreadOps();
    return realLen;
  }
169798
public static void readFully(ReadableByteChannel channel, ByteBuffer dst) throws IOException {
    int expected = dst.remaining();
    while (dst.hasRemaining()) {
      if (channel.read(dst) < 0) {
        throw new EOFException(String.format("Not enough bytes in channel (expected %d).",
          expected));
      }
    }
  }