public static void skipFully ( InputStream in , long bytes ) throws IOException { if ( bytes < 0 ) { throw new IllegalArgumentException ( "Can't skip " + bytes + " bytes" ) ; } long remaining = bytes ; while ( remaining > 0 ) { long skipped = in . skip ( remaining ) ; if ( skipped <= 0 ) { throw new EOFException ( "Reached EOF while trying to skip a total of " + bytes ) ; } remaining -= skipped ; } }
Provide a skip fully method . Either skips the requested number of bytes or throws an IOException ;