本文整理了Java中org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.setEncoding()
方法的一些代码示例,展示了ZipArchiveOutputStream.setEncoding()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipArchiveOutputStream.setEncoding()
方法的具体详情如下:
包路径:org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
类名称:ZipArchiveOutputStream
方法名:setEncoding
[英]The encoding to use for filenames and the file comment.
For a list of possible values see http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html. Defaults to UTF-8.
[中]用于文件名和文件注释的编码。
有关可能值的列表,请参见http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html。默认为UTF-8。
代码示例来源:origin: org.apache.commons/commons-compress
final ZipArchiveOutputStream zip = new ZipArchiveOutputStream(out);
if (actualEncoding != null) {
zip.setEncoding(actualEncoding);
代码示例来源:origin: stackoverflow.com
ZipArchiveOutputStream ostream = ...; // Your initialization code here
ostream.setEncoding("Cp437"); // This should handle your "special" characters
ostream.setFallbackToUTF8(true); // For "unknown" characters!
ostream.setUseLanguageEncodingFlag(true);
ostream.setCreateUnicodeExtraFields(
ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NOT_ENCODEABLE);
代码示例来源:origin: naver/ngrinder
zos.setEncoding(charsetName);
FileInputStream fis = null;
代码示例来源:origin: org.codehaus.plexus/plexus-archiver
zipArchiveOutputStream.setEncoding( encoding );
zipArchiveOutputStream.setCreateUnicodeExtraFields( this.getUnicodeExtraFieldPolicy() );
zipArchiveOutputStream.setMethod(
代码示例来源:origin: org.codehaus.plexus/plexus-archiver
new ZipArchiveOutputStream( bufferedOutputStream( fileOutputStream( getDestFile(), "jar" ) ) );
zipArchiveOutputStream.setEncoding( getEncoding() );
if ( isCompress() )
代码示例来源:origin: org.apache.ant/ant-compress
/**
* @param stream the stream to write to, should be buffered
* @param encoding the encoding of the entry names
*/
@Override
public ArchiveOutputStream getArchiveStream(OutputStream stream,
String encoding)
throws IOException {
ZipArchiveOutputStream o = new ZipArchiveOutputStream(stream);
o.setEncoding(encoding);
return o;
}
代码示例来源:origin: org.apache.ant/ant-compress
/**
* @param file the file to write to
* @param encoding the encoding of the entry names
*/
@Override
public ArchiveOutputStream getArchiveOutputStream(File file,
String encoding)
throws IOException {
ZipArchiveOutputStream o = new ZipArchiveOutputStream(file);
o.setEncoding(encoding);
return o;
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
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);
}
代码示例来源:origin: USPTO/PatentPublicData
@Override
public void open() throws IOException {
outputZip = new ZipArchiveOutputStream(filePath.toFile());
outputZip.setEncoding("UTF-8");
outputZip.setLevel(9);
ZipArchiveEntry zipEntry = new ZipArchiveEntry("corpus.xml");
outputZip.putArchiveEntry(zipEntry);
}
代码示例来源:origin: com.haulmont.reports/reports-core
protected byte[] zipContent(Map<String, Object> stringObjectMap) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
zipOutputStream.setEncoding(ENCODING);
for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()) {
byte[] data = (byte[]) entry.getValue();
ArchiveEntry archiveEntry = newStoredEntry(entry.getKey(), data);
zipOutputStream.putArchiveEntry(archiveEntry);
zipOutputStream.write(data);
zipOutputStream.closeArchiveEntry();
}
zipOutputStream.close();
return byteArrayOutputStream.toByteArray();
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
@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();
}
代码示例来源:origin: org.apache.wookie/wookie-parser
/**
* Packages the source file/folder up as a new Zip file
* @param source the source file or folder to be zipped
* @param target the zip file to create
* @throws IOException
*/
public static void repackZip(File source, File target) throws IOException{
ZipArchiveOutputStream out = new ZipArchiveOutputStream(target);
out.setEncoding("UTF-8");
for(File afile: source.listFiles()){
pack(afile,out, "");
}
out.flush();
out.close();
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
@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();
}
代码示例来源:origin: org.alfresco/alfresco-repository
@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);
}
代码示例来源:origin: Alfresco/alfresco-repository
@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);
}
代码示例来源:origin: com.haulmont.cuba/cuba-global
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();
}
代码示例来源:origin: org.alfresco/alfresco-repository
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);
}
代码示例来源:origin: Alfresco/alfresco-repository
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);
}
代码示例来源:origin: com.haulmont.reports/reports-core
@Override
public byte[] exportReports(Collection<Report> reports) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(byteArrayOutputStream);
try {
zipOutputStream.setMethod(ZipArchiveOutputStream.STORED);
zipOutputStream.setEncoding(ENCODING);
for (Report report : reports) {
try {
byte[] reportBytes = exportReport(report);
ArchiveEntry singleReportEntry = newStoredEntry(replaceForbiddenCharacters(report.getName()) + ".zip", reportBytes);
zipOutputStream.putArchiveEntry(singleReportEntry);
zipOutputStream.write(reportBytes);
zipOutputStream.closeArchiveEntry();
} catch (IOException e) {
throw new ReportingException(String.format("Exception occurred while exporting report [%s]", report.getName()), e);
}
}
} finally {
IOUtils.closeQuietly(zipOutputStream);
}
return byteArrayOutputStream.toByteArray();
}
代码示例来源:origin: stackoverflow.com
import java.io.*;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
public class ZipFiles {
public static void main(String[] args) throws Exception{
ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(new FileOutputStream("测试.zip"));
zipOut.setEncoding("Cp437"); // This should handle your "special" characters
zipOut.setFallbackToUTF8(true); // For "unknown" characters!
zipOut.setUseLanguageEncodingFlag(true);
zipOut.setCreateUnicodeExtraFields(
ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NOT_ENCODEABLE);
zipOut.putArchiveEntry(new ZipArchiveEntry("测试.xml"));
zipOut.putArchiveEntry(new ZipArchiveEntry("test.xml"));
zipOut.closeArchiveEntry();
zipOut.flush();
zipOut.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!