private void buildTemplatedMetadataFile ( String path ) throws IOException { try ( InputStream is = getClass ( ) . getResourceAsStream ( "/content-package-template/" + path ) ) { String xmlContent = IOUtils . toString ( is ) ; for ( Map . Entry < String , Object > entry : metadata . getVars ( ) . entrySet ( ) ) { xmlContent = StringUtils . replace ( xmlContent , "{{" + entry . getKey ( ) + "}}" , StringEscapeUtils . escapeXml10 ( entry . getValue ( ) . toString ( ) ) ) ; } zip . putNextEntry ( new ZipEntry ( path ) ) ; try { zip . write ( xmlContent . getBytes ( Charsets . UTF_8 ) ) ; } finally { zip . closeEntry ( ) ; } } }
Read template file from classpath replace variables and store it in the zip stream .