public static void write ( final String templateFilename , final Map < String , Object > data , final Writer writer ) { Template tmpl = null ; try { /*- * note that we don't need to cache templates by ourselves since getTemplate() does that internally already */ tmpl = conf . getTemplate ( templateFilename ) ; } catch ( FileNotFoundException e1 ) { String errMsg = "FileNotFoundException: template file '" + templateFilename + "' not found" ; log . error ( "{}: {}" , errMsg , e1 . getMessage ( ) ) ; throw new AwsMockException ( errMsg , e1 ) ; } catch ( IOException e ) { String errMsg = "IOException: failed to getTemplate (filename is " + templateFilename + ")" ; log . error ( "{}: {}" , errMsg , e . getMessage ( ) ) ; throw new AwsMockException ( errMsg , e ) ; } try { tmpl . process ( data , writer ) ; } catch ( TemplateException e ) { StringBuilder dataDescription = new StringBuilder ( ) ; if ( null != data ) { for ( Map . Entry < String , Object > entry : data . entrySet ( ) ) { dataDescription . append ( entry . getKey ( ) + " - " + entry . getValue ( ) ) . append ( ' ' ) ; } } String errMsg = "TemplateException: failed to process template '" + templateFilename + "', with data: " + dataDescription . toString ( ) + " The probable cause could be un-matching of key-values for that template. " ; log . error ( "{}: {}" , errMsg , e . getMessage ( ) ) ; throw new AwsMockException ( errMsg , e ) ; } catch ( IOException e ) { String errMsg = "IOException: failed to process template and write to writer. " ; log . error ( "{}: {}" , errMsg , e . getMessage ( ) ) ; throw new AwsMockException ( errMsg , e ) ; } }
Process with given template + data and then put result to writer .