format/src/main/java/com/github/sadikovi/riff/io/InStream.java
/**
   * Skip number of bytes.
   * If offset is within current buffer, position is updated, otherwise source is asked to advance
   * k number of bytes and new buffer is allocated.
   * @param bytes number of bytes to skip
   * @return actual number of bytes skipped
   * @throws IOException
   */
Skip number of bytes.
If offset is within current buffer, position is updated, otherwise source is asked to advance
k number of bytes and new buffer is allocated.
@param bytes number of bytes to skip
@return actual number of bytes skipped
@throws IOException
Skip number of bytes . If offset is within current buffer position is updated otherwise source is asked to advance k number of bytes and new buffer is allocated . @param bytes number of bytes to skip @return actual number of bytes skipped @throws IOException
@Override
  public long skip(long bytes) throws IOException {
    if (bytes < 0) {
      throw new IndexOutOfBoundsException("Negative length: " + bytes);
    }
    if (uncompressed.remaining() >= bytes) {
      uncompressed.position(uncompressed.position() + (int) bytes);
      return bytes;
    }
    if (codec == null) {
      int nextPosition = source.position() + (int) (bytes - uncompressed.remaining());
      if (nextPosition > source.length()) {
        bytes = source.length() - source.position();
        source.seek(source.length());
      } else {
        bytes = nextPosition - source.position();
        source.seek(nextPosition);
      }
      readChunk();
      return bytes;
    } else {
      int diff = (int) (bytes - uncompressed.remaining());
      while (source.length() > source.position()) {
        readChunk();
        if (uncompressed.remaining() >= diff) {
          uncompressed.position(uncompressed.position() + diff);
          return bytes;
        }
        diff -= uncompressed.remaining();
      }
      return bytes - diff;
    }
  }
@ Override public long skip ( long bytes ) throws IOException { if ( bytes < 0 ) { throw new IndexOutOfBoundsException ( "Negative length: " + bytes ) ; } if ( uncompressed . remaining ( ) >= bytes ) { uncompressed . position ( uncompressed . position ( ) + ( int ) bytes ) ; return bytes ; } if ( codec == null ) { int nextPosition = source . position ( ) + ( int ) ( bytes - uncompressed . remaining ( ) ) ; if ( nextPosition > source . length ( ) ) { bytes = source . length ( ) - source . position ( ) ; source . seek ( source . length ( ) ) ; } else { bytes = nextPosition - source . position ( ) ; source . seek ( nextPosition ) ; } readChunk ( ) ; return bytes ; } else { int diff = ( int ) ( bytes - uncompressed . remaining ( ) ) ; while ( source . length ( ) > source . position ( ) ) { readChunk ( ) ; if ( uncompressed . remaining ( ) >= diff ) { uncompressed . position ( uncompressed . position ( ) + diff ) ; return bytes ; } diff -= uncompressed . remaining ( ) ; } return bytes - diff ; } }
Skip number of bytes.
Skip number of bytes .
// if we have some bytes left in buffer, just shift position, but only if we have some remaining // bytes left after this operation // at this point, we are short on bytes to skip, we need to indicate to source that we require // seeking to new offset, after this refill buffer // for uncompressed input stream, we just reposition pointer in source // at this point we reached EOF, just set it, so next copy will result in 0 copied bytes // for compressed input stream, we will have to read bytes in order to determine skip position // we can skip all requested bytes, return the same number // at this point source enountered EOF, return read bytes so far