format/src/main/java/com/github/sadikovi/riff/io/InStream.java
/**
   * Read method copies bytes from underlying buffer into provided array. If necessary, it will
   * buffer source for more data. If last batch is being read, fewer bytes might be returned, but,
   * otherwise, it will ensure reading all bytes that were requested.
   * @param bytes byte array to copy into
   * @param offset offset
   * @param length length to copy
   * @return number of bytes actually being copied into array
   * @throws IOException
   */
Read method copies bytes from underlying buffer into provided array. If necessary, it will
buffer source for more data. If last batch is being read, fewer bytes might be returned, but,
otherwise, it will ensure reading all bytes that were requested.
Read method copies bytes from underlying buffer into provided array . If necessary it will buffer source for more data . If last batch is being read fewer bytes might be returned but otherwise it will ensure reading all bytes that were requested .
@Override
  public int read(byte[] bytes, int offset, int length) throws IOException {
    if (length < 0) {
      throw new IndexOutOfBoundsException("Negative length: " + length);
    }
    int bytesRead = Math.min(uncompressed.remaining(), length);
    uncompressed.get(bytes, offset, bytesRead);
    int bytesSoFar = length;
    length -= bytesRead;
    while (length > 0) {
      readChunk();
      offset += bytesRead;
      bytesRead = Math.min(uncompressed.remaining(), length);
      if (bytesRead == 0) return bytesSoFar - length;
      uncompressed.get(bytes, offset, bytesRead);
      length -= bytesRead;
    }
    return bytesSoFar;
  }
@ Override public int read ( byte [ ] bytes , int offset , int length ) throws IOException { if ( length < 0 ) { throw new IndexOutOfBoundsException ( "Negative length: " + length ) ; } int bytesRead = Math . min ( uncompressed . remaining ( ) , length ) ; uncompressed . get ( bytes , offset , bytesRead ) ; int bytesSoFar = length ; length -= bytesRead ; while ( length > 0 ) { readChunk ( ) ; offset += bytesRead ; bytesRead = Math . min ( uncompressed . remaining ( ) , length ) ; if ( bytesRead == 0 ) return bytesSoFar - length ; uncompressed . get ( bytes , offset , bytesRead ) ; length -= bytesRead ; } return bytesSoFar ; }
Read method copies bytes from underlying buffer into provided array.
Read method copies bytes from underlying buffer into provided array .
// keep track of maximum number of bytes we have copied into array // refill buffer // no more bytes can be read, EOF is reached