List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveOutputStream setEncoding
public void setEncoding(final String encoding)
From source file:com.fjn.helper.common.io.file.zip.zip.ZipArchiveHelper.java
/** * ?/*w w w . j a va 2 s . co m*/ * * @param out * @param filepathList */ public static void zip(OutputStream out, List<String> filepathList, String filenameEncoding) { ZipArchiveOutputStream zipout = new ZipArchiveOutputStream(out); zipout.setEncoding(filenameEncoding); for (String path : filepathList) { if (StringUtil.isNull(path)) continue; File file = new File(path); if (!file.exists()) continue; zipFile(zipout, file, ""); } }
From source file:com.haulmont.cuba.core.sys.logging.LogArchiver.java
public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException { if (!logFile.exists()) { throw new FileNotFoundException(); }//from w w w .ja v a 2 s .com ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(outputStream); zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED); zipOutputStream.setEncoding(ZIP_ENCODING); byte[] content = getTailBytes(logFile); ArchiveEntry archiveEntry = newTailArchive(logFile.getName(), content); zipOutputStream.putArchiveEntry(archiveEntry); zipOutputStream.write(content); zipOutputStream.closeArchiveEntry(); zipOutputStream.close(); }
From source file:com.haulmont.cuba.core.sys.logging.LogArchiver.java
public static void writeArchivedLogToStream(File logFile, OutputStream outputStream) throws IOException { if (!logFile.exists()) { throw new FileNotFoundException(); }/*from w w w . j a v a 2 s.c o m*/ File tempFile = File.createTempFile(FilenameUtils.getBaseName(logFile.getName()) + "_log_", ".zip"); ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(tempFile); zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED); zipOutputStream.setEncoding(ZIP_ENCODING); ArchiveEntry archiveEntry = newArchive(logFile); zipOutputStream.putArchiveEntry(archiveEntry); FileInputStream logFileInput = new FileInputStream(logFile); IOUtils.copyLarge(logFileInput, zipOutputStream); logFileInput.close(); zipOutputStream.closeArchiveEntry(); zipOutputStream.close(); FileInputStream tempFileInput = new FileInputStream(tempFile); IOUtils.copyLarge(tempFileInput, outputStream); tempFileInput.close(); FileUtils.deleteQuietly(tempFile); }
From source file:com.hw.util.CompressUtils.java
public static final void zip(String compressPath, String[] needCompressPaths) { File compressFile = new File(compressPath); List<File> files = new ArrayList<File>(); for (String needCompressPath : needCompressPaths) { File needCompressFile = new File(needCompressPath); if (!needCompressFile.exists()) { continue; }//from w w w.j a va2s .c o m files.add(needCompressFile); } try { ZipArchiveOutputStream zaos = null; try { zaos = new ZipArchiveOutputStream(compressFile); zaos.setUseZip64(Zip64Mode.AsNeeded); zaos.setEncoding("GBK"); for (File file : files) { addFilesToCompression(zaos, file, ""); } } catch (IOException e) { throw e; } finally { IOUtils.closeQuietly(zaos); } } catch (Exception e) { FileUtils.deleteQuietly(compressFile); throw new RuntimeException("", e); } }
From source file:com.daphne.es.maintain.editor.web.controller.utils.CompressUtils.java
public static final void zip(String compressPath, String[] needCompressPaths) { File compressFile = new File(compressPath); List<File> files = Lists.newArrayList(); for (String needCompressPath : needCompressPaths) { File needCompressFile = new File(needCompressPath); if (!needCompressFile.exists()) { continue; }// ww w . ja v a 2s .c o m files.add(needCompressFile); } try { ZipArchiveOutputStream zaos = null; try { zaos = new ZipArchiveOutputStream(compressFile); zaos.setUseZip64(Zip64Mode.AsNeeded); zaos.setEncoding("GBK"); for (File file : files) { addFilesToCompression(zaos, file, ""); } } catch (IOException e) { throw e; } finally { IOUtils.closeQuietly(zaos); } } catch (Exception e) { FileUtils.deleteQuietly(compressFile); throw new RuntimeException("", e); } }
From source file:com.ikon.util.ArchiveUtils.java
/** * Recursively create ZIP archive from directory */// w w w .j a v a2s.c om public static void createZip(File path, String root, OutputStream os) throws IOException { log.debug("createZip({}, {}, {})", new Object[] { path, root, os }); if (path.exists() && path.canRead()) { ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(os); zaos.setComment("Generated by openkm"); zaos.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS); zaos.setUseLanguageEncodingFlag(true); zaos.setFallbackToUTF8(true); zaos.setEncoding("UTF-8"); // Prevents java.util.zip.ZipException: ZIP file must have at least one entry ZipArchiveEntry zae = new ZipArchiveEntry(root + "/"); zaos.putArchiveEntry(zae); zaos.closeArchiveEntry(); createZipHelper(path, zaos, root); zaos.flush(); zaos.finish(); zaos.close(); } else { throw new IOException("Can't access " + path); } log.debug("createZip: void"); }
From source file:com.openkm.util.ArchiveUtils.java
/** * Recursively create ZIP archive from directory *///from w w w . ja v a 2 s . co m public static void createZip(File path, String root, OutputStream os) throws IOException { log.debug("createZip({}, {}, {})", new Object[] { path, root, os }); if (path.exists() && path.canRead()) { ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(os); zaos.setComment("Generated by OpenKM"); zaos.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS); zaos.setUseLanguageEncodingFlag(true); zaos.setFallbackToUTF8(true); zaos.setEncoding("UTF-8"); // Prevents java.util.zip.ZipException: ZIP file must have at least one entry ZipArchiveEntry zae = new ZipArchiveEntry(root + "/"); zaos.putArchiveEntry(zae); zaos.closeArchiveEntry(); createZipHelper(path, zaos, root); zaos.flush(); zaos.finish(); zaos.close(); } else { throw new IOException("Can't access " + path); } log.debug("createZip: void"); }
From source file:com.openkm.util.ArchiveUtils.java
/** * Create ZIP archive from file/* www . jav a2 s .c om*/ */ public static void createZip(File path, OutputStream os) throws IOException { log.debug("createZip({}, {})", new Object[] { path, os }); if (path.exists() && path.canRead()) { ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(os); zaos.setComment("Generated by OpenKM"); zaos.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS); zaos.setUseLanguageEncodingFlag(true); zaos.setFallbackToUTF8(true); zaos.setEncoding("UTF-8"); log.debug("FILE {}", path); ZipArchiveEntry zae = new ZipArchiveEntry(path.getName()); zaos.putArchiveEntry(zae); FileInputStream fis = new FileInputStream(path); IOUtils.copy(fis, zaos); fis.close(); zaos.closeArchiveEntry(); zaos.flush(); zaos.finish(); zaos.close(); } else { throw new IOException("Can't access " + path); } log.debug("createZip: void"); }
From source file:com.silverpeas.util.ZipManager.java
/** * Mthode permettant la cration et l'organisation d'un fichier zip en lui passant directement un * flux d'entre/* w ww .j av a 2s. c om*/ * * @param inputStream - flux de donnes enregistrer dans le zip * @param filePathNameToCreate - chemin et nom du fichier port par les donnes du flux dans le * zip * @param outfilename - chemin et nom du fichier zip creer ou complter * @throws IOException */ public static void compressStreamToZip(InputStream inputStream, String filePathNameToCreate, String outfilename) throws IOException { ZipArchiveOutputStream zos = null; try { zos = new ZipArchiveOutputStream(new FileOutputStream(outfilename)); zos.setFallbackToUTF8(true); zos.setCreateUnicodeExtraFields(NOT_ENCODEABLE); zos.setEncoding("UTF-8"); zos.putArchiveEntry(new ZipArchiveEntry(filePathNameToCreate)); IOUtils.copy(inputStream, zos); zos.closeArchiveEntry(); } finally { if (zos != null) { IOUtils.closeQuietly(zos); } } }
From source file:com.silverpeas.util.ZipManager.java
/** * Mthode compressant un dossier de faon rcursive au format zip. * * @param folderToZip - dossier compresser * @param zipFile - fichier zip creer//from w ww . j a v a2s . c o m * @return la taille du fichier zip gnr en octets * @throws FileNotFoundException * @throws IOException */ public static long compressPathToZip(File folderToZip, File zipFile) throws IOException { ZipArchiveOutputStream zos = null; try { // cration du flux zip zos = new ZipArchiveOutputStream(new FileOutputStream(zipFile)); zos.setFallbackToUTF8(true); zos.setCreateUnicodeExtraFields(NOT_ENCODEABLE); zos.setEncoding(CharEncoding.UTF_8); Collection<File> folderContent = FileUtils.listFiles(folderToZip, null, true); for (File file : folderContent) { String entryName = file.getPath().substring(folderToZip.getParent().length() + 1); entryName = FilenameUtils.separatorsToUnix(entryName); zos.putArchiveEntry(new ZipArchiveEntry(entryName)); InputStream in = new FileInputStream(file); IOUtils.copy(in, zos); zos.closeArchiveEntry(); IOUtils.closeQuietly(in); } } finally { if (zos != null) { IOUtils.closeQuietly(zos); } } return zipFile.length(); }