@Test public void replaceTemplateVariables_nested() { Map<String, Object> variables = new HashMap<>(); variables.put("appId.simpleId", "blabla"); String template = "trallalitrallala = ${${appId.simpleId}.xxx}.oink"; String resolved = IOUtil.replaceTemplateVariables(template, variables); assertThat(resolved).isEqualTo("trallalitrallala = ${blabla.xxx}.oink"); }
public static void replaceTemplateVariables(final File destinationFile, final File templateFile, final String characterSet, final Map<?, ?> variables) throws IOException { if (!destinationFile.isAbsolute()) throw new IllegalArgumentException("destinationFile is not absolute: " + destinationFile.getPath()); logger.info("Creating destination file \""+destinationFile.getAbsolutePath()+"\" from template \""+templateFile.getAbsolutePath()+"\"."); final File destinationDirectory = destinationFile.getParentFile(); if (!destinationDirectory.exists()) { logger.info("Directory for destination file does not exist. Creating it: " + destinationDirectory.getAbsolutePath()); if (!destinationDirectory.mkdirs()) logger.error("Creating directory for destination file failed: " + destinationDirectory.getAbsolutePath()); } final InputStream fin = castStream(templateFile.createInputStream()); try { final Reader fr = characterSet != null ? new InputStreamReader(fin, characterSet) : new InputStreamReader(fin); try { final OutputStream fos = castStream(destinationFile.createOutputStream()); try { final Writer fw = characterSet != null ? new OutputStreamWriter(fos, characterSet) : new OutputStreamWriter(fos); try { replaceTemplateVariables(fw, fr, variables); } finally { fw.close(); } } finally { fos.close(); } } finally { fr.close(); } } finally { fin.close(); } }
IOUtil { public static void replaceTemplateVariables(final File destinationFile, final File templateFile, final String characterSet, final Map<?, ?> variables) throws IOException { if (!destinationFile.isAbsolute()) throw new IllegalArgumentException("destinationFile is not absolute: " + destinationFile.getPath()); logger.info("Creating destination file \""+destinationFile.getAbsolutePath()+"\" from template \""+templateFile.getAbsolutePath()+"\"."); final File destinationDirectory = destinationFile.getParentFile(); if (!destinationDirectory.exists()) { logger.info("Directory for destination file does not exist. Creating it: " + destinationDirectory.getAbsolutePath()); if (!destinationDirectory.mkdirs()) logger.error("Creating directory for destination file failed: " + destinationDirectory.getAbsolutePath()); } final InputStream fin = castStream(templateFile.createInputStream()); try { final Reader fr = characterSet != null ? new InputStreamReader(fin, characterSet) : new InputStreamReader(fin); try { final OutputStream fos = castStream(destinationFile.createOutputStream()); try { final Writer fw = characterSet != null ? new OutputStreamWriter(fos, characterSet) : new OutputStreamWriter(fos); try { replaceTemplateVariables(fw, fr, variables); } finally { fw.close(); } } finally { fos.close(); } } finally { fr.close(); } } finally { fin.close(); } } }
IOUtil { public static void replaceTemplateVariables(final File destinationFile, final File templateFile, final String characterSet, final Map<?, ?> variables) throws IOException { if (!destinationFile.isAbsolute()) throw new IllegalArgumentException("destinationFile is not absolute: " + destinationFile.getPath()); logger.info("Creating destination file \""+destinationFile.getAbsolutePath()+"\" from template \""+templateFile.getAbsolutePath()+"\"."); final File destinationDirectory = destinationFile.getParentFile(); if (!destinationDirectory.exists()) { logger.info("Directory for destination file does not exist. Creating it: " + destinationDirectory.getAbsolutePath()); if (!destinationDirectory.mkdirs()) logger.error("Creating directory for destination file failed: " + destinationDirectory.getAbsolutePath()); } final InputStream fin = castStream(templateFile.createInputStream()); try { final Reader fr = characterSet != null ? new InputStreamReader(fin, characterSet) : new InputStreamReader(fin); try { final OutputStream fos = castStream(destinationFile.createOutputStream()); try { final Writer fw = characterSet != null ? new OutputStreamWriter(fos, characterSet) : new OutputStreamWriter(fos); try { replaceTemplateVariables(fw, fr, variables); } finally { fw.close(); } } finally { fos.close(); } } finally { fr.close(); } } finally { fin.close(); } } private  IOUtil(); }
IOUtil { public static void replaceTemplateVariables(final File destinationFile, final File templateFile, final String characterSet, final Map<?, ?> variables) throws IOException { if (!destinationFile.isAbsolute()) throw new IllegalArgumentException("destinationFile is not absolute: " + destinationFile.getPath()); logger.info("Creating destination file \""+destinationFile.getAbsolutePath()+"\" from template \""+templateFile.getAbsolutePath()+"\"."); final File destinationDirectory = destinationFile.getParentFile(); if (!destinationDirectory.exists()) { logger.info("Directory for destination file does not exist. Creating it: " + destinationDirectory.getAbsolutePath()); if (!destinationDirectory.mkdirs()) logger.error("Creating directory for destination file failed: " + destinationDirectory.getAbsolutePath()); } final InputStream fin = castStream(templateFile.createInputStream()); try { final Reader fr = characterSet != null ? new InputStreamReader(fin, characterSet) : new InputStreamReader(fin); try { final OutputStream fos = castStream(destinationFile.createOutputStream()); try { final Writer fw = characterSet != null ? new OutputStreamWriter(fos, characterSet) : new OutputStreamWriter(fos); try { replaceTemplateVariables(fw, fr, variables); } finally { fw.close(); } } finally { fos.close(); } } finally { fr.close(); } } finally { fin.close(); } } private  IOUtil(); @Deprecated static String getRelativePath(File baseDir, final String file); @Deprecated static String getRelativePath(final File baseDir, final File file); @Deprecated static String getRelativePath(final String baseDir, final String file); static String simplifyPath(final File path); static long transferStreamData(final InputStream in, final OutputStream out, final long inputOffset, final long inputLen); static long transferStreamData(final InputStream in, final OutputStream out, final long inputOffset, final long inputLen, final ProgressMonitor monitor); static long transferStreamData(final InputStream in, final OutputStream out); @Deprecated static boolean deleteDirectoryRecursively(final File dir); @Deprecated static boolean deleteDirectoryRecursively(final String dir); static synchronized File createUniqueIncrementalFolder(final File rootFolder, final String prefix); static synchronized File createUniqueRandomFolder(final File rootFolder, final String prefix, final long maxIterations, final long uniqueOutOf); static File createUniqueRandomFolder(final File rootFolder, final String prefix); static File getFile(final File file, final String ... subDirs); static void writeTextFile(final File file, final String text, final String encoding); static String readTextFile(final File f, final String encoding); static String readTextFile(final File f); static void writeTextFile(final File file, final String text); static String readTextFile(final InputStream in, final String encoding); static String readTextFile(final InputStream in); static String getFileExtension(final String fileName); static String getFileNameWithoutExtension(final String fileName); static File getTempDir(); static File createUserTempDir(final String prefix, final String suffix); static File getUserTempDir(final String prefix, final String suffix); static File getUserHome(); static boolean compareInputStreams(final InputStream inputStream1, final InputStream inputStream2); static boolean compareFiles(final File f1, final File f2); static void copyDirectory(final File sourceDirectory, final File destinationDirectory); static void copyDirectory(final File sourceDirectory, final File destinationDirectory, final FileFilter fileFilter); static void copyResource(final Class<?> sourceResClass, final String sourceResName, final String destinationFilename); static void copyResource(final Class<?> sourceResClass, final String sourceResName, final File destinationFile); static void copyFile(final File sourceFile, final File destinationFile); static void copyFile(final File sourceFile, final File destinationFile, final ProgressMonitor monitor); static String addFinalSlash(final String directory); static void replaceTemplateVariables(final File destinationFile, final File templateFile, final String characterSet, final Map<?, ?> variables); static String replaceTemplateVariables(final String template, final Map<?, ?> variables); static void replaceTemplateVariables(final Writer writer, final Reader reader, final Map<?, ?> variables); static byte[] getBytesFromFile(final File file); static File createCollisionFile(final File file); static void deleteOrFail(final File file); static int readOrFail(final InputStream in); static void readOrFail(final InputStream in, final byte[] buf, int off, int len); static byte[] longToBytes(final long value); static long bytesToLong(final byte[] bytes); static byte[] intToBytes(final int value); static int bytesToInt(final byte[] bytes); }
IOUtil { public static void replaceTemplateVariables(final File destinationFile, final File templateFile, final String characterSet, final Map<?, ?> variables) throws IOException { if (!destinationFile.isAbsolute()) throw new IllegalArgumentException("destinationFile is not absolute: " + destinationFile.getPath()); logger.info("Creating destination file \""+destinationFile.getAbsolutePath()+"\" from template \""+templateFile.getAbsolutePath()+"\"."); final File destinationDirectory = destinationFile.getParentFile(); if (!destinationDirectory.exists()) { logger.info("Directory for destination file does not exist. Creating it: " + destinationDirectory.getAbsolutePath()); if (!destinationDirectory.mkdirs()) logger.error("Creating directory for destination file failed: " + destinationDirectory.getAbsolutePath()); } final InputStream fin = castStream(templateFile.createInputStream()); try { final Reader fr = characterSet != null ? new InputStreamReader(fin, characterSet) : new InputStreamReader(fin); try { final OutputStream fos = castStream(destinationFile.createOutputStream()); try { final Writer fw = characterSet != null ? new OutputStreamWriter(fos, characterSet) : new OutputStreamWriter(fos); try { replaceTemplateVariables(fw, fr, variables); } finally { fw.close(); } } finally { fos.close(); } } finally { fr.close(); } } finally { fin.close(); } } private  IOUtil(); @Deprecated static String getRelativePath(File baseDir, final String file); @Deprecated static String getRelativePath(final File baseDir, final File file); @Deprecated static String getRelativePath(final String baseDir, final String file); static String simplifyPath(final File path); static long transferStreamData(final InputStream in, final OutputStream out, final long inputOffset, final long inputLen); static long transferStreamData(final InputStream in, final OutputStream out, final long inputOffset, final long inputLen, final ProgressMonitor monitor); static long transferStreamData(final InputStream in, final OutputStream out); @Deprecated static boolean deleteDirectoryRecursively(final File dir); @Deprecated static boolean deleteDirectoryRecursively(final String dir); static synchronized File createUniqueIncrementalFolder(final File rootFolder, final String prefix); static synchronized File createUniqueRandomFolder(final File rootFolder, final String prefix, final long maxIterations, final long uniqueOutOf); static File createUniqueRandomFolder(final File rootFolder, final String prefix); static File getFile(final File file, final String ... subDirs); static void writeTextFile(final File file, final String text, final String encoding); static String readTextFile(final File f, final String encoding); static String readTextFile(final File f); static void writeTextFile(final File file, final String text); static String readTextFile(final InputStream in, final String encoding); static String readTextFile(final InputStream in); static String getFileExtension(final String fileName); static String getFileNameWithoutExtension(final String fileName); static File getTempDir(); static File createUserTempDir(final String prefix, final String suffix); static File getUserTempDir(final String prefix, final String suffix); static File getUserHome(); static boolean compareInputStreams(final InputStream inputStream1, final InputStream inputStream2); static boolean compareFiles(final File f1, final File f2); static void copyDirectory(final File sourceDirectory, final File destinationDirectory); static void copyDirectory(final File sourceDirectory, final File destinationDirectory, final FileFilter fileFilter); static void copyResource(final Class<?> sourceResClass, final String sourceResName, final String destinationFilename); static void copyResource(final Class<?> sourceResClass, final String sourceResName, final File destinationFile); static void copyFile(final File sourceFile, final File destinationFile); static void copyFile(final File sourceFile, final File destinationFile, final ProgressMonitor monitor); static String addFinalSlash(final String directory); static void replaceTemplateVariables(final File destinationFile, final File templateFile, final String characterSet, final Map<?, ?> variables); static String replaceTemplateVariables(final String template, final Map<?, ?> variables); static void replaceTemplateVariables(final Writer writer, final Reader reader, final Map<?, ?> variables); static byte[] getBytesFromFile(final File file); static File createCollisionFile(final File file); static void deleteOrFail(final File file); static int readOrFail(final InputStream in); static void readOrFail(final InputStream in, final byte[] buf, int off, int len); static byte[] longToBytes(final long value); static long bytesToLong(final byte[] bytes); static byte[] intToBytes(final int value); static int bytesToInt(final byte[] bytes); static final String CHARSET_NAME_UTF_8; static final long GIGABYTE; static final String COLLISION_FILE_NAME_INFIX; }