Java Code Examples for org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream#setCreateUnicodeExtraFields()

The following examples show how to use org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream#setCreateUnicodeExtraFields() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZipExport.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Exports the specified folder content
 * 
 * @param transaction Transaction with all informations about the export
 * @param pdfConversion True if the pdf conversion has to be used instead of
 *        the original files
 *        
 * @return The Stream of the zip archive
 */
public ByteArrayOutputStream process(FolderHistory transaction, boolean pdfConversion) {
	FolderDAO folderDao = (FolderDAO) Context.get().getBean(FolderDAO.class);
	Folder folder = folderDao.findFolder(transaction.getFolderId());
	this.userId = transaction.getUserId();
	this.startFolderId = folder.getId();
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	zos = new ZipArchiveOutputStream(bos);
	zos.setMethod(ZipEntry.DEFLATED);
	zos.setEncoding("UTF-8");
	zos.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
	zos.setUseLanguageEncodingFlag(true);

	try {
		appendChildren(folder, 0, pdfConversion, transaction.getSessionId());
	} finally {
		try {
			zos.flush();
			zos.close();
		} catch (Throwable e) {
			e.printStackTrace();
		}

	}

	/*
	 * Record the export event
	 */
	transaction.setEvent(FolderEvent.EXPORTED.toString());
	folderDao.saveFolderHistory(folder, transaction);

	return bos;
}
 
Example 2
Source File: ACPExportPackageHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void startExport()
{
    // ALF-2016
    zipStream = new ZipArchiveOutputStream(outputStream);
    // NOTE: This encoding allows us to workaround bug...
    //       http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
    zipStream.setEncoding("UTF-8");
    zipStream.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
    zipStream.setUseLanguageEncodingFlag(true);
    zipStream.setFallbackToUTF8(true);
    zipStream.setUseZip64(Zip64Mode.Always);
}
 
Example 3
Source File: ZipDownloadExporter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void start(final ExporterContext context)
{
    zipStream = new ZipArchiveOutputStream(outputStream);
    // NOTE: This encoding allows us to workaround bug...
    //       http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
    zipStream.setEncoding("UTF-8");
    zipStream.setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy.ALWAYS);
    zipStream.setUseLanguageEncodingFlag(true);
    zipStream.setFallbackToUTF8(true);
}
 
Example 4
Source File: ArchiveUtils.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create ZIP archive from file
 */
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");
}
 
Example 5
Source File: ArchiveUtils.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Recursively create ZIP archive from directory
 */
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");
}