本文整理汇总了Java中org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.setEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java ZipArchiveOutputStream.setEncoding方法的具体用法?Java ZipArchiveOutputStream.setEncoding怎么用?Java ZipArchiveOutputStream.setEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
的用法示例。
在下文中一共展示了ZipArchiveOutputStream.setEncoding方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeArchivedLogTailToStream
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public static void writeArchivedLogTailToStream(File logFile, OutputStream outputStream) throws IOException {
if (!logFile.exists()) {
throw new FileNotFoundException();
}
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();
}
示例2: exportFolder
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
@Override
public byte[] exportFolder(Folder folder) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
String xml = createXStream().toXML(folder);
byte[] xmlBytes = xml.getBytes(StandardCharsets.UTF_8);
ArchiveEntry zipEntryDesign = newStoredEntry("folder.xml", xmlBytes);
zipOutputStream.putArchiveEntry(zipEntryDesign);
zipOutputStream.write(xmlBytes);
try {
zipOutputStream.closeArchiveEntry();
} catch (Exception ex) {
throw new RuntimeException(String.format("Exception occurred while exporting folder %s.", folder.getName()));
}
zipOutputStream.close();
return byteArrayOutputStream.toByteArray();
}
示例3: exportEntitiesToZIP
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
@Override
public byte[] exportEntitiesToZIP(Collection<? extends Entity> entities) {
String json = entitySerialization.toJson(entities, null, EntitySerializationOption.COMPACT_REPEATED_ENTITIES);
byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
zipOutputStream.setEncoding(StandardCharsets.UTF_8.name());
ArchiveEntry singleDesignEntry = newStoredEntry("entities.json", jsonBytes);
try {
zipOutputStream.putArchiveEntry(singleDesignEntry);
zipOutputStream.write(jsonBytes);
zipOutputStream.closeArchiveEntry();
} catch (Exception e) {
throw new RuntimeException("Error on creating zip archive during entities export", e);
} finally {
IOUtils.closeQuietly(zipOutputStream);
}
return byteArrayOutputStream.toByteArray();
}
示例4: startExport
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
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);
}
示例5: start
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
@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);
}
示例6: makeZip
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public static void makeZip() throws IOException, ArchiveException{
File f1 = new File("D:/compresstest.txt");
File f2 = new File("D:/test1.xml");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//ArchiveOutputStream ostemp = new ArchiveStreamFactory().createArchiveOutputStream("zip", baos);
ZipArchiveOutputStream ostemp = new ZipArchiveOutputStream(baos);
ostemp.setEncoding("GBK");
ostemp.putArchiveEntry(new ZipArchiveEntry(f1.getName()));
IOUtils.copy(new FileInputStream(f1), ostemp);
ostemp.closeArchiveEntry();
ostemp.putArchiveEntry(new ZipArchiveEntry(f2.getName()));
IOUtils.copy(new FileInputStream(f2), ostemp);
ostemp.closeArchiveEntry();
ostemp.finish();
ostemp.close();
// final OutputStream out = new FileOutputStream("D:/testcompress.zip");
final OutputStream out = new FileOutputStream("D:/中文名字.zip");
ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out);
os.putArchiveEntry(new ZipArchiveEntry("打包.zip"));
baos.writeTo(os);
os.closeArchiveEntry();
baos.close();
os.finish();
os.close();
}
示例7: createZip
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
/**
* 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");
}
示例8: writeArchivedLogToStream
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public static void writeArchivedLogToStream(File logFile, OutputStream outputStream) throws IOException {
if (!logFile.exists()) {
throw new FileNotFoundException();
}
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);
}
示例9: createTestZipFile
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public File createTestZipFile(String encoding) {
OutputStream outputStream = null;
try {
File zipfile = TempFileProvider.createTempFile("zip_output", ".zip");
outputStream = new FileOutputStream(zipfile);
ZipArchiveOutputStream logicalZip = (ZipArchiveOutputStream) new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, outputStream);
if (StringUtils.isNotBlank(encoding)) {
logicalZip.setEncoding(encoding);
}
addFileToZip("file1.txt", logicalZip);
addFileToZip("file2.txt", logicalZip);
addFileToZip("folder.with.dots.in.the.name/", logicalZip);
addFileToZip("folder.with.dots.in.the.name/file5.txt", logicalZip);
addFileToZip("folder.with.dots.in.the.name/file4.txt", logicalZip);
addFileToZip("folder1/", logicalZip);
addFileToZip("folder1/file3.txt", logicalZip);
addFileToZip("file_ending_with_a_dot.", logicalZip);
addFileToZip("file+with+plus+in+it.txt", logicalZip);
addFileToZip("file\"qoute_in_it.txt", logicalZip);
addFileToZip("file_with_&_in_it.txt", logicalZip);
// addFileToZip("1. Överenskommelser/5. Utskickade tåkar under 2013/608 Primärvården VGR PNV Tåk FM-kontor Lokalvård PV Mölnlycke barnmott, Mödrabarnhälsa i haga, Psykologi.pdf", logicalZip);
logicalZip.finish();
return zipfile;
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
IOUtils.closeQuietly(outputStream);
}
}
示例10: zip
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; //导入方法依赖的package包/类
public void zip( File fileOrDirectoryToZip, File targetFile, Charset charset ) {
try {
ZipArchiveOutputStream stream = new ZipArchiveOutputStream( targetFile );
stream.setEncoding( charset.name() );
stream.setCreateUnicodeExtraFields( ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS );
compress( fileOrDirectoryToZip, stream );
} catch( IOException e ) {
throw new UncheckedIOException( e );
}
}