Author: chatellier
Date: 2009-05-01 16:01:12 +0000 (Fri, 01 May 2009)
New Revision: 1457
Modified:
lutinutil/trunk/src/main/java/org/codelutin/util/ZipUtil.java
Log:
Improve zip code
Modified: lutinutil/trunk/src/main/java/org/codelutin/util/ZipUtil.java
===================================================================
--- lutinutil/trunk/src/main/java/org/codelutin/util/ZipUtil.java 2009-04-30 12:26:16 UTC (rev 1456)
+++ lutinutil/trunk/src/main/java/org/codelutin/util/ZipUtil.java 2009-05-01 16:01:12 UTC (rev 1457)
@@ -77,7 +77,7 @@
* Uncompress zipped file in targetDir.
*
* @param file the zip source file
- * @param targetDir the destination direcotory
+ * @param targetDir the destination directory
* @return return last entry name
* @throws IOException if any problem while uncompressing
*/
@@ -342,7 +342,9 @@
newFiles.add(name);
}
} finally {
- if (zip != null) zip.close();
+ if (zip != null) {
+ zip.close();
+ }
}
}
@@ -369,8 +371,8 @@
* @param file location of zip file
* @param targetDir destination directory
* @param toTreate list of relative local path of entries to treate
- * @param renameFrom {@link #uncompressAndRename(java.io.File, java.io.File, String, String)}
- * @param renameTo {@link #uncompressAndRename(java.io.File, java.io.File, String, String)}
+ * @param renameFrom {@link #uncompressAndRename(File, File, String, String)}
+ * @param renameTo {@link #uncompressAndRename(File, File, String, String)}
* @return return last entry name
* @throws IOException if nay exception while operation
*/
@@ -378,8 +380,9 @@
String result = "";
ZipInputStream in = new ZipInputStream(new FileInputStream(file));
ZipEntry entry;
- if (toTreate == null || toTreate.isEmpty())
+ if (toTreate == null || toTreate.isEmpty()) {
return ZipUtil.uncompressAndRename(file, targetDir, renameFrom, renameTo);
+ }
boolean rename = renameFrom != null && renameTo != null;
@@ -391,11 +394,16 @@
result = convertToLocalEntryName(name);
}
- log.debug("open [" + name + "] : " + result);
- if (!toTreate.contains(result)) continue;
+ if (log.isDebugEnabled()) {
+ log.debug("open [" + name + "] : " + result);
+ }
+ if (!toTreate.contains(result)) {
+ continue;
+ }
-
- log.debug("copy [" + name + "] : " + result);
+ if (log.isDebugEnabled()) {
+ log.debug("copy [" + name + "] : " + result);
+ }
File target = new File(targetDir, result);
if (entry.isDirectory()) {
target.mkdirs();
@@ -415,6 +423,9 @@
return result;
}
+ /**
+ * @deprecated unused/undocumented function
+ */
public static String convertToZipEntryName(String txt, boolean isDir) {
String s = txt.replaceAll(LOCAL_SEP_PATTERN, ZIP_SEP);
while (s.startsWith(ZIP_SEP)) {
@@ -424,7 +435,7 @@
}
- public static String convertToLocalEntryName(String txt) {
+ protected static String convertToLocalEntryName(String txt) {
String s = txt.replaceAll(ZIP_SEP_PATTERN, LOCAL_SEP_PATTERN);
if (s.endsWith(ZIP_SEP)) {
s = s.substring(0, s.length() - 1);
@@ -432,5 +443,3 @@
return s;
}
}
-
-