/** * This file is part of Archiv-Editor. * * The software Archiv-Editor serves as a client user interface for working with * the Person Data Repository. See: pdr.bbaw.de * * The software Archiv-Editor was developed at the Berlin-Brandenburg Academy * of Sciences and Humanities, Jägerstr. 22/23, D-10117 Berlin. * www.bbaw.de * * Copyright (C) 2010-2013 Berlin-Brandenburg Academy * of Sciences and Humanities * * The software Archiv-Editor was developed by @author: Christoph Plutte. * * Archiv-Editor is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Archiv-Editor is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Archiv-Editor. * If not, see <http://www.gnu.org/licenses/lgpl-3.0.html>. */ package org.bbaw.pdr.ae.common.utils; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.bbaw.pdr.ae.common.CommonActivator; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; public class CopyDirectory { /** Logger. */ public static final ILog ILOGGER = CommonActivator.getDefault().getLog(); public static void copyDirectory(File srcPath, File dstPath) throws IOException { if (srcPath.isDirectory()) { if (!dstPath.exists()) { dstPath.mkdir(); } String files[] = srcPath.list(); for (int i = 0; i < files.length; i++) { copyDirectory(new File(srcPath, files[i]), new File(dstPath, files[i])); } } else { if (!srcPath.exists()) { // System.out.println("File or directory does not exist."); // System.exit(0); } else { InputStream in = new FileInputStream(srcPath); OutputStream out = new FileOutputStream(dstPath); // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } } // System.out.println("Directory copied."); } public static void unZipIt(InputStream zipInputStream, String outputFolder) { byte[] buffer = new byte[1024]; try { // create output directory is not exists File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } // get the zip file content ZipInputStream zis = new ZipInputStream( zipInputStream); // get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder + File.separator + fileName); IStatus ae = new Status(IStatus.INFO, CommonActivator.PLUGIN_ID, "file unzip : " + newFile.getAbsoluteFile()); ILOGGER.log(ae); // create all non exists folders // else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); if (ze.isDirectory()) { if (!newFile.exists()) { newFile.mkdir(); } } else { if (!newFile.exists()) { newFile.createNewFile(); } FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); System.out.println("Done"); } catch (IOException ex) { ex.printStackTrace(); } } }