public static List < String > getElements ( File file , String charset ) { List < String > list = new ArrayList <> ( ) ; try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( java . nio . file . Files . newInputStream ( file . toPath ( ) ) , charset ) ) ) { StringBuilder sb = new StringBuilder ( 4096 ) ; String line ; int cnt = 0 ; final Pattern whitespacesOnly = Pattern . compile ( "^\\s*$" ) ; while ( ( line = br . readLine ( ) ) != null ) { if ( cnt > ( TOP_COUNT ) ) { if ( whitespacesOnly . matcher ( line ) . matches ( ) ) { list . add ( sb . toString ( ) ) ; sb . setLength ( 0 ) ; } else { sb . append ( line ) ; sb . append ( ' ' ) ; } } ++ cnt ; } if ( sb . length ( ) > 0 ) { list . add ( sb . toString ( ) ) ; } } catch ( IOException e ) { String msg = new StringBuilder ( 512 ) . append ( "Cannot feed the data into sonar, details: '" ) . append ( e ) . append ( "'" ) . toString ( ) ; LOG . error ( msg ) ; } return list ; }
get all DrMemory elements from file