|
From: <pat...@us...> - 2011-02-18 03:30:47
|
Revision: 1219
http://cishell.svn.sourceforge.net/cishell/?rev=1219&view=rev
Author: pataphil
Date: 2011-02-18 03:30:41 +0000 (Fri, 18 Feb 2011)
Log Message:
-----------
* Added ZipUtilities.zipFilesWithNames()
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/ZipUtilities.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ZipUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ZipUtilities.java 2011-02-18 03:29:48 UTC (rev 1218)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ZipUtilities.java 2011-02-18 03:30:41 UTC (rev 1219)
@@ -23,7 +23,7 @@
throws ZipIOException {
try {
for (File file : files) {
- writeFileToZipFile(file, zipOut);
+ writeFileToZipFile(file, file.getName(), zipOut);
}
zipOut.close();
@@ -44,13 +44,38 @@
}
}
- public static void writeFileToZipFile(File file, ZipOutputStream zipOut)
+ public static void zipFilesWithNames(
+ Map<File, String> fileToZippedName, ZipOutputStream zipOut) throws ZipIOException {
+ try {
+ for (File file : fileToZippedName.keySet()) {
+ writeFileToZipFile(file, fileToZippedName.get(file), zipOut);
+ }
+
+ zipOut.close();
+ } catch (IOException e) {
+ throw new ZipIOException(e.getMessage(), e);
+ }
+ }
+
+ public static void zipFilesWithNames(
+ Map<File, String> fileToZippedName, File targetZipFile) throws ZipIOException {
+ try {
+ zipFilesWithNames(
+ fileToZippedName,
+ new ZipOutputStream(
+ new BufferedOutputStream(new FileOutputStream(targetZipFile))));
+ } catch (FileNotFoundException e) {
+ throw new ZipIOException(e.getMessage(), e);
+ }
+ }
+
+ public static void writeFileToZipFile(File file, String zippedName, ZipOutputStream zipOut)
throws ZipIOException {
try {
byte data[] = new byte[BUFFER_SIZE];
BufferedInputStream fileInput =
new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE);
- ZipEntry entry = new ZipEntry(file.getName());
+ ZipEntry entry = new ZipEntry(zippedName);
zipOut.putNextEntry(entry);
int count;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|