use of org.apache.tools.zip.ZipEntry in project translationstudio8 by heartsome.
the class ZipFileExporter2 method write.
/**
* Write the passed resource to the current archive.
* @param resource
* org.eclipse.core.resources.IFile
* @param destinationPath
* java.lang.String
* @exception java.io.IOException
* @exception org.eclipse.core.runtime.CoreException
*/
public void write(IFile resource, String destinationPath) throws IOException, CoreException {
ZipEntry newEntry = new ZipEntry(destinationPath);
write(newEntry, resource);
}
use of org.apache.tools.zip.ZipEntry in project translationstudio8 by heartsome.
the class ZipFileExporter2 method addDbFile.
public void addDbFile(File file, String destinationPath) throws IOException {
ZipEntry newEntry = new ZipEntry(destinationPath);
writeFile(newEntry, file);
}
use of org.apache.tools.zip.ZipEntry in project tdi-studio-se by Talend.
the class ZipFileUtils method unZip.
public static String unZip(String unZipFileName, String destFileName) {
File unzipFile = new File(unZipFileName);
if (destFileName == null || destFileName.trim().length() == 0) {
destFileName = unzipFile.getParent();
}
File destFile;
ZipFile zipFile = null;
try {
zipFile = new ZipFile(unzipFile, "GBK");
for (Enumeration entries = zipFile.getEntries(); entries.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) entries.nextElement();
destFile = new File(destFileName, entry.getName());
unZipFile(destFile, zipFile, entry);
}
} catch (Exception e) {
ExceptionHandler.process(e);
return e.getMessage();
} finally {
try {
assert zipFile != null;
zipFile.close();
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
return null;
}
use of org.apache.tools.zip.ZipEntry in project PublicCMS-preview by sanluan.
the class ZipUtils method unzip.
/**
* @param zipFilePath
* @param targetPath
* @param overwrite
* @throws IOException
*/
public static void unzip(String zipFilePath, String targetPath, boolean overwrite) throws IOException {
ZipFile zipFile = new ZipFile(zipFilePath, ENCODING);
Enumeration<? extends ZipEntry> entryEnum = zipFile.getEntries();
if (null != entryEnum) {
while (entryEnum.hasMoreElements()) {
ZipEntry zipEntry = entryEnum.nextElement();
if (zipEntry.isDirectory()) {
File dir = new File(targetPath + File.separator + zipEntry.getName());
dir.mkdirs();
} else {
File targetFile = new File(targetPath + File.separator + zipEntry.getName());
if (!targetFile.exists() || overwrite) {
targetFile.getParentFile().mkdirs();
try (InputStream inputStream = zipFile.getInputStream(zipEntry);
FileOutputStream outputStream = new FileOutputStream(targetFile);
FileLock fileLock = outputStream.getChannel().tryLock()) {
StreamUtils.copy(inputStream, outputStream);
}
}
}
}
}
zipFile.close();
}
use of org.apache.tools.zip.ZipEntry in project PublicCMS-preview by sanluan.
the class ZipUtils method compress.
/**
* @param file
* @param out
* @param basedir
* @throws IOException
*/
private static void compress(Path sourceFilePath, ZipOutputStream out, String basedir) throws IOException {
if (Files.isDirectory(sourceFilePath)) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(sourceFilePath)) {
for (Path entry : stream) {
BasicFileAttributes attrs = Files.readAttributes(entry, BasicFileAttributes.class);
String fullName = BLANK.equals(basedir) ? entry.toFile().getName() : basedir + SEPARATOR + entry.toFile().getName();
if (attrs.isDirectory()) {
ZipEntry zipEntry = new ZipEntry(fullName + SEPARATOR);
out.putNextEntry(zipEntry);
compress(entry, out, fullName);
} else {
compressFile(entry.toFile(), out, fullName);
}
}
} catch (IOException e) {
}
} else {
compressFile(sourceFilePath.toFile(), out, sourceFilePath.toFile().getName());
}
}
Aggregations