package gov.nih.nci.cagrid.data.upgrades.from1pt0;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import com.atomicobject.haste.framework.Step;

/** 
 *  UnzipOldServiceStep
 *  Step to unzip the old service
 * 
 * @author <A HREF="MAILTO:ervin@bmi.osu.edu">David W. Ervin</A>  * 
 * @created Feb 20, 2007 
 * @version $Id: UnzipOldServiceStep.java,v 1.1 2007-02-20 21:03:17 dervin Exp $ 
 */
public class UnzipOldServiceStep extends Step {
	private String testDir;
	
	public UnzipOldServiceStep(String testDir) {
		super();
		this.testDir = testDir;
	}
	

	public void runStep() throws Throwable {
		FileInputStream zipFileInput = new FileInputStream(testDir + File.separator + "resources" + File.separator + "CaGridTutorialService1.0.zip");
		ZipInputStream zipInput = new ZipInputStream(zipFileInput);
		ZipEntry entry = null;
		while ((entry = zipInput.getNextEntry()) != null) {
			String name = entry.getName();
			File outFile = new File(testDir + File.separator + name);
			if (entry.isDirectory()) {
				outFile.mkdirs();
			} else {
				outFile.createNewFile();
				BufferedOutputStream fileOut = new BufferedOutputStream(
					new FileOutputStream(testDir + File.separator + name));
				copyStreams(zipInput, fileOut);
				fileOut.flush();
				fileOut.close();
			}
		}
		zipInput.close();
	}
	
	
	private void copyStreams(ZipInputStream input, BufferedOutputStream output) throws IOException {
		byte[] temp = new byte[8192];
		int read = -1;
		while ((read = input.read(temp)) != -1) {
			output.write(temp, 0, read);
		}
	}
}

@@ -56,183 +56,49 @@
 ort 
-java.io.BufferedOutputStream;%0Aimport java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.util.zip.ZipEntry
+gov.nih.nci.cagrid.common.ZipUtilities
 ;%0A
+%0A
 impo
@@ -109,31 +109,15 @@
 ava.
-util.zip.ZipInputStream
+io.File
 ;%0A%0Ai
@@ -370,17 +370,17 @@
 ava,v 1.
-1
+2
  2007-02
@@ -385,18 +385,18 @@
 02-2
-0 21:03:17
+1 16:48:56
  der
@@ -626,54 +626,33 @@
 File
-InputStream zipFileInput = new FileInputStream
+ zippedService = new File
 (tes
@@ -748,794 +748,58 @@
 %09Zip
-InputStream zipInput = new ZipInputStream(zipFileInput);%0A%09%09ZipEntry entry = null;%0A%09%09while ((entry = zipInput.getNextEntry()) != null) %7B%0A%09%09%09String name = entry.getName();%0A%09%09%09File outFile = new File(testDir + File.separator + name);%0A%09%09%09if (entry.isDirectory()) %7B%0A%09%09%09%09outFile.mkdirs();%0A%09%09%09%7D else %7B%0A%09%09%09%09outFile.createNewFile();%0A%09%09%09%09BufferedOutputStream fileOut = new BufferedOutputStream(%0A%09%09%09%09%09new FileOutputStream(testDir + File.separator + name));%0A%09%09%09%09copyStreams(zipInput, fileOut);%0A%09%09%09%09fileOut.flush();%0A%09%09%09%09fileOut.close();%0A%09%09%09%7D%0A%09%09%7D%0A%09%09zipInput.close();%0A%09%7D%0A%09%0A%09%0A%09private void copyStreams(ZipInputStream input, BufferedOutputStream output) throws IOException %7B%0A%09%09byte%5B%5D temp = new byte%5B8192%5D;%0A%09%09int read = -1;%0A%09%09while ((read = input.read(temp)) != -1) %7B%0A%09%09%09output.write(temp, 0, read);%0A%09%09%7D
+Utilities.unzip(zippedService, new File(testDir));
 %0A%09%7D%0A

make use of zip utils