private static long estimateLineCount ( final File file , final int byReadingLineNum ) throws UncheckedIOException { final Holder < ZipFile > outputZipFile = new Holder <> ( ) ; InputStream is = null ; BufferedReader br = null ; try { is = openFile ( outputZipFile , file ) ; br = Objectory . createBufferedReader ( is ) ; int cnt = 0 ; String line = null ; long bytes = 0 ; while ( cnt < byReadingLineNum && ( line = br . readLine ( ) ) != null ) { bytes += line . getBytes ( ) . length ; cnt ++ ; } return cnt == 0 ? 0 : ( file . length ( ) / ( bytes / cnt == 0 ? 1 : bytes / cnt ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } finally { closeQuietly ( is ) ; closeQuietly ( outputZipFile . value ( ) ) ; Objectory . recycle ( br ) ; } }
Estimate the total line count of the file by reading the specified line count ahead .