public int read(byte[] bytes,int offset,int count) throws IOException {
  if (bytes == null)   throw new IllegalArgumentException("bytes cannot be null.");
  int startingCount=count;
  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=optional(count);
    if (copyCount == -1) {
      if (startingCount == count)       return -1;
      break;
    }
    if (position == limit)     break;
  }
  return startingCount - count;
}

public int read ( byte [ ] bytes , int offset , int count ) throws IOException { if ( bytes == null ) throw new IllegalArgumentException ( "bytes cannot be null." ) ; int startingCount = count ; 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 = optional ( count ) ; if ( copyCount == - 1 ) { if ( startingCount == count ) return - 1 ; break ; } if ( position == limit ) break ; } return startingCount - count ; }
reads count bytes or less and writes them to the specified byte [ ] , starting at offset , and returns the number of bytes read or - 1 if no more bytes are available .
