//*********************************************************************************
// class tig.zip
// Software released under the General Public License (version 2 or later), available at
// http://www.gnu.org/copyleft/gpl.html
//*********************************************************************************
package tig;
import tig.GeneralConstants;
import java.io.*;
import java.util.*;
import java.util.zip.*;
/******************************************************************
Contains methods used to zip and unzip a set of files.
<BR>Written from code found in "Thinking in java", 2nd edition.
@author Thierry Graff
@history dec xx 2001 creation.
@history apr 21 2002 integrated to tig package.
@todo
*****************************************************************/
public abstract class Zip implements GeneralConstants{
/*
public static void main(String[] args){
try{
//zipFiles("test.zip", args);
unzipFile("test.zip", "unzippedFiles" + FS + "dest");
String destDir = "C:\\Documents and Settings\\airbus\\Bureau\\doc Thierry\\tmp\\testSave\\unzipped\\desc";
//unzipFile("test.zip", destDir);
}
catch(IOException ioe){
}
}
*/
//**************** zipFiles ********************************
/** Zips the input files to a single Zip archive. */
public static void zipFiles(String outputFile, String[] inputFiles) throws IOException {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile));
BufferedReader in;
int c;
for(int i = 0; i < inputFiles.length; i++) {
System.out.println("Writing file " + inputFiles[i]);
in = new BufferedReader(new FileReader(inputFiles[i]));
out.putNextEntry(new ZipEntry(inputFiles[i]));
while((c = in.read()) != -1) out.write(c);
in.close();
}
out.close();
}
//**************** unzipFiles ********************************
/** Unzips the file to the destination directory. */
public static void unzipFile(String zipFile, String destinationDir) throws IOException {
File destDir = new File(destinationDir);
destDir.mkdirs();
ZipInputStream in = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
ZipEntry ze;
BufferedWriter out;
int x;
while((ze = in.getNextEntry()) != null) {
System.out.println("Reading file " + ze);
out = new BufferedWriter(new FileWriter(destinationDir + FS + ze.toString()));
while((x = in.read()) != -1) out.write(x);
out.close();
}
in.close();
}
}// end class Zip