private List < Object > getFilePreviews ( final String [ ] fileList , final String locationFull , final IStreamProvider streamProvider , final boolean renderResultsAsHtml ) { final List < Object > files = new ArrayList <> ( ) ; InputStream csvInputStream = null ; try { for ( final String fileName : fileList ) { final Map < String , Object > file = new HashMap <> ( ) ; file . put ( "name" , fileName ) ; final String filePath = locationFull + "/" + fileName ; csvInputStream = streamProvider . getFileInputStream ( filePath ) ; final Scanner rowScanner = new Scanner ( csvInputStream , StandardCharsets . UTF_8 . toString ( ) ) ; final List < Object > lines = new ArrayList <> ( ) ; int lineNumber = 0 ; while ( rowScanner . hasNextLine ( ) && lineNumber < ReportalMailCreator . NUM_PREVIEW_ROWS ) { final String csvLine = rowScanner . nextLine ( ) ; final String [ ] data = csvLine . split ( "\",\"" ) ; final List < String > line = new ArrayList <> ( ) ; for ( final String item : data ) { String column = item . replace ( "\"" , "" ) ; if ( ! renderResultsAsHtml ) { column = StringEscapeUtils . escapeHtml ( column ) ; } line . add ( column ) ; } lines . add ( line ) ; lineNumber ++ ; } file . put ( "content" , lines ) ; if ( rowScanner . hasNextLine ( ) ) { file . put ( "hasMore" , true ) ; } files . add ( file ) ; rowScanner . close ( ) ; } } catch ( final Exception e ) { logger . debug ( "Error encountered while processing files in " + locationFull , e ) ; } finally { IOUtils . closeQuietly ( csvInputStream ) ; } return files ; }
Returns a list of file Objects that contain a name property with the file name a content property with the lines in the file and a hasMore property if the file contains more than NUM_PREVIEW_ROWS lines .