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

The following examples show how to use org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream#setFallbackToUTF8() . 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: 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 2
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 3
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 4
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");
}