Read a byte array from the given offset and size in the buffer

This will <em>consume</em> the given {@link ByteBuffer}.
194320
public static byte[] readBytes(ByteBuffer buffer, int offset, int size) {
        final byte[] dest = new byte[size];
        buffer.get(dest, offset, size);
        return dest;
    }
1033387
public void readBytes (Object to, long offset, int count) throws KryoException {
		int copyCount = Math.min(limit - position, count);
		while (true) {
			unsafe.copyMemory(null, bufferAddress + position, to, offset, copyCount);
			position += copyCount;
			count -= copyCount;
			if (count == 0) break;
			offset += copyCount;
			copyCount = Math.min(count, capacity);
			require(copyCount);
		}
		byteBuffer.position(position);
	}
718135
public static byte[] readArray(ReadableBuffer buffer) {
    Preconditions.checkNotNull(buffer, "buffer");
    int length = buffer.readableBytes();
    byte[] bytes = new byte[length];
    buffer.readBytes(bytes, 0, length);
    return bytes;
  }
741221
@Override
    public int read (byte[] b, int off, int len) throws IOException {
        if (b == null) {
            throw new NullPointerException();
        } else if (off < 0 || len < 0 || len > b.length - off) {
            throw new IndexOutOfBoundsException();
        } else if (len == 0) {
            return 0;
        }

        int c;
        if (nonBlockingEnabled)
            c = this.read(0L);
        else
            c = in.read();

        if (c == -1) {
            return -1;
        }
        b[off] = (byte)c;
        return 1;
    }
134780
private int ensureBuffer(int offset, int length) throws IOException {
		final int lastPos = offset + length - 1;
		final int desiredSize = ((lastPos / BUFFER_SIZE) + 1) * BUFFER_SIZE;
		final int currentSize = this.buffer.length;

		if (desiredSize > currentSize) {
			final byte[] readBuffer = new byte[desiredSize - currentSize];
			final int count = this.in.read(readBuffer);

			if (count > 0) {
				final byte[] newBuffer = new byte[currentSize + count];
				System.arraycopy(this.buffer, 0, newBuffer, 0, currentSize);
				System.arraycopy(readBuffer, 0, newBuffer, currentSize, count);
				this.buffer = newBuffer;
			}
			return (lastPos < this.buffer.length) ? length : length - (lastPos - this.buffer.length + 1);
		}
		return length;
	}
735494
public void readBytes (Object to, long offset, int count) throws KryoException {
		int copyCount = Math.min(limit - position, count);
		while (true) {
			unsafe.copyMemory(buffer, byteArrayBaseOffset + position, to, offset, copyCount);
			position += copyCount;
			count -= copyCount;
			if (count == 0) break;
			offset += copyCount;
			copyCount = Math.min(count, capacity);
			require(copyCount);
		}
	}
857395
@Override
  public int read(byte[] buffer, int offset, int length) throws IOException
  {
    int b = -1;

    if (_isPartDone)
      return -1;

    int i = 0;
    // Need the last peek or would miss the initial '\n'
    while (_peekOffset + 1 < _peekLength && length > 0) {
      buffer[offset + i++] = _peek[_peekOffset++];
      length--;
    }

    while (i < length && (b = read()) >= 0) {
      boolean hasCr = false;

      if (b == '\r') {
        hasCr = true;
        b = read();

        // XXX: Macintosh?
        if (b != '\n') {
          buffer[offset + i++] = (byte) '\r';
          _peek[0] = (byte) b;
          _peekOffset = 0;
          _peekLength = 1;
          continue;
        }
      }
      else if (b != '\n') {
        buffer[offset + i++] = (byte) b;
        continue;
      }

      int j;
      for (j = 0;
           j < _boundaryLength && (b = read()) >= 0 && _boundaryBuffer[j] == b;
           j++) {
      }

      if (j == _boundaryLength) {
        _isPartDone = true;
        if ((b = read()) == '-') {
          if ((b = read()) == '-') {
            _isDone = true;
            _isComplete = true;
          }
        }

        for (; b > 0 && b != '\r' && b != '\n'; b = read()) {
        }
        if (b == '\r' && (b = read()) != '\n') {
          _peek[0] = (byte) b;
          _peekOffset = 0;
          _peekLength = 1;
        }

        return i > 0 ? i : -1;
      }

      _peekLength = 0;
      if (hasCr && i + 1 < length) {
        buffer[offset + i++] = (byte) '\r';
        buffer[offset + i++] = (byte) '\n';
      }
      else if (hasCr) {
        buffer[offset + i++] = (byte) '\r';
        _peek[_peekLength++] = (byte) '\n';
      }
      else {
        buffer[offset + i++] = (byte) '\n';
      }

      int k = 0;
      while (k < j && i + 1 < length)
        buffer[offset + i++] = _boundaryBuffer[k++];

      while (k < j)
        _peek[_peekLength++] = _boundaryBuffer[k++];

      _peek[_peekLength++] = (byte) b;
      _peekOffset = 0;
    }

    if (i <= 0) {
      _isPartDone = true;
      if (b < 0)
        _isDone = true;
      return -1;
    }
    else {
      return i;
    }
  }
960946
public byte[] getByteArray(Integer offset)
   {
      byte[] result = null;

      if (offset != null)
      {
         result = m_map.get(offset);
      }

      return (result);
   }
577824
public synchronized int read(byte b[], int off, int len) throws IOException
    {
        int avail=_avail-_pos;
        if (avail <=0)
        {
            fill();
            avail=_avail-_pos;
        }

        if (avail <=0)
            len=-1;
        else
        {
            len=(avail < len) ? avail : len;
            System.arraycopy(_buf,_pos,b,off,len);
            _pos +=len;
        }
        
        return len;
    }
148667
public int read(byte[] b, int off, int len) throws IOException
    {
        if (_expectContinues!=null)
            expectContinues();
        return super.read(b, off, len);
    }
977705
public void toBytes(byte[] b, int offset) {
    ByteConverter.float8(b, offset, x);
    ByteConverter.float8(b, offset + 8, y);
  }
7776
@Override
    public int read(byte[] buffer, int offset, int length) throws IOException {
        abortIfNeeded();
        int numBytesRead;
        // If no more bytes are available, do not read any bytes into the buffer
        if(this.virtualAvailable <= 0) {
            numBytesRead = -1;
        } else {
            // If the desired read length is greater than the number of available bytes,
            // shorten the read length to the number of available bytes.
            if(length > this.virtualAvailable) {
                // If the number of available bytes is greater than the maximum value of a 32 bit int, then
                // read as many bytes as an int can.
                length = (this.virtualAvailable < Integer.MAX_VALUE) ? (int)this.virtualAvailable : Integer.MAX_VALUE;
            }
            // Read bytes into the buffer.
            numBytesRead = this.decryptedContents.read(buffer, offset, length);
        }
        // If we were able to read bytes, decrement the number of bytes available to be read.
        if(numBytesRead != -1) {
            this.virtualAvailable -= numBytesRead;
        } else {
            // If we've reached the end of the stream, close it
            this.virtualAvailable = 0;
            close();
        }
        return numBytesRead;
    }
188019
@Override
    public int read(final ByteBuffer destination) throws IOException {

        // Precondition checks
        this.checkClosed();
        if (destination == null) {
            throw new IllegalArgumentException("Destination buffer must be supplied");
        }

        // Init
        final int spaceInBuffer = destination.remaining();
        final int numBytesRemainingInContent, numBytesToRead;

        // Sync up before getting at shared mutable state
        synchronized (this) {
            numBytesRemainingInContent = this.contents.length - this.position;

            // Set position was greater than the size? Just return.
            if (numBytesRemainingInContent <= 0) {
                return -1;
            }

            // We'll read in either the number of bytes remaining in content or the amount of space in the buffer,
            // whichever is smaller
            numBytesToRead = numBytesRemainingInContent >= spaceInBuffer ? spaceInBuffer : numBytesRemainingInContent;
            // Copy a sub-array of the bytes we'll put into the buffer
            destination.put(this.contents, this.position, numBytesToRead);

            // Set the new position
            this.position += numBytesToRead;
        }

        // Return the number of bytes read
        return numBytesToRead;
    }
339236
public byte[] getBytes(int offset,
                           int length) throws IOException {
        if ((offset + length) > fsize) {
            throw new java.io.IOException("Reached EOF");
        }

        byte[] ret = new byte[length];
        System.arraycopy(file, offset, ret, 0, length);
        return ret;
    }
487842
private static byte[] toByteArray(final ByteBuffer buffer)
  {
    if (buffer.hasArray()
        && buffer.arrayOffset() == 0
        && buffer.position() == 0
        && buffer.array().length == buffer.limit()) {
      return buffer.array();
    } else {
      final byte[] retVal = new byte[buffer.remaining()];
      buffer.duplicate().get(retVal);
      return retVal;
    }
  }
673436
public int getBytes(byte[] buf, int offset, int length)
    {
        if (length>unconsumedData())
            length=unconsumedData();
        System.arraycopy(_buf,_pos,buf,offset,length);
        _pos+=length;
        return length;
    }
540975
@Override
	public int read(byte[] buffer, int offset, int len) throws IOException {
		return this.in.read(buffer, offset, len);
	}