public static List < String > createStatementsFromFileResource ( Resource sqlResource , LastScriptLineDecorator lineDecorator ) { BufferedReader reader = null ; StringBuffer buffer ; List < String > stmts = new ArrayList <> ( ) ; try { if ( log . isDebugEnabled ( ) ) { log . debug ( "Create statements from SQL file: " + sqlResource . getFile ( ) . getAbsolutePath ( ) ) ; } reader = new BufferedReader ( new InputStreamReader ( sqlResource . getInputStream ( ) ) ) ; buffer = new StringBuffer ( ) ; String line ; while ( reader . ready ( ) ) { line = reader . readLine ( ) ; if ( line != null && ! line . trim ( ) . startsWith ( SQL_COMMENT ) && line . trim ( ) . length ( ) > 0 ) { if ( line . trim ( ) . endsWith ( getStatementEndingCharacter ( lineDecorator ) ) ) { if ( lineDecorator != null ) { buffer . append ( lineDecorator . decorate ( line ) ) ; } else { buffer . append ( line ) ; } String stmt = buffer . toString ( ) . trim ( ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Found statement: " + stmt ) ; } stmts . add ( stmt ) ; buffer . setLength ( 0 ) ; buffer = new StringBuffer ( ) ; } else { buffer . append ( line ) ; //more lines to come for this statement add line break buffer . append ( "\n" ) ; } } } } catch ( IOException e ) { throw new CitrusRuntimeException ( "Resource could not be found - filename: " + sqlResource , e ) ; } finally { if ( reader != null ) { try { reader . close ( ) ; } catch ( IOException e ) { log . warn ( "Warning: Error while closing reader instance" , e ) ; } } } return stmts ; }
Reads SQL statements from external file resource . File resource can hold several multi - line statements and comments .