Index: lutinutil/src/java/org/codelutin/util/ZipUtil.java diff -u lutinutil/src/java/org/codelutin/util/ZipUtil.java:1.2 lutinutil/src/java/org/codelutin/util/ZipUtil.java:1.3 --- lutinutil/src/java/org/codelutin/util/ZipUtil.java:1.2 Fri Aug 25 16:59:15 2006 +++ lutinutil/src/java/org/codelutin/util/ZipUtil.java Fri Jan 5 15:10:31 2007 @@ -23,9 +23,9 @@ * Created: 24 août 2006 10:13:35 * * @author poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update: $Date: 2006/08/25 16:59:15 $ + * Last update: $Date: 2007/01/05 15:10:31 $ * by : $Author: bpoussin $ */ @@ -82,11 +82,37 @@ * @throws IOException */ public static String uncompress(File file, File targetDir) throws IOException { + String result = uncompressAndRename(file, targetDir, null, null); + return result; + } + + /** + * uncompress zipped file in targetDir, and rename uncompressed file if + * necessary. If renameFrom or renameTo is null no renaming is done + *
+ * file in zip use / to separate directory and not begin with / + * each directory ended with / + * + * @param file + * @param regionDirectory + * @param renameFrom pattern to permit rename file before uncompress it + * @param renameTo new name for file if renameFrom is applicable to it + * you can use $1, $2, ... if you have '(' ')' in renameFrom + * @return return last entry name + * @throws IOException + */ + public static String uncompressAndRename(File file, File targetDir, String renameFrom, String renameTo) throws IOException { String result = ""; ZipInputStream in = new ZipInputStream(new FileInputStream(file)); ZipEntry entry = null; while ((entry = in.getNextEntry()) != null) { String name = entry.getName(); + if (renameFrom != null && renameTo != null) { + name = name.replaceAll(renameFrom, renameTo); + if (log.isDebugEnabled()) { + log.debug("rename " + entry.getName() + " -> " + name); + } + } result = name; File target = new File(targetDir, name); if (entry.isDirectory()) { @@ -102,9 +128,9 @@ } } in.close(); - return result; + return result; } - + /** * Compress 'includes' files in zipFile. If file in includes is directory * only the directory is put in zipFile, not the file contained in directory