本文整理了Java中org.apache.poi.openxml4j.opc.internal.ZipHelper
类的一些代码示例,展示了ZipHelper
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipHelper
类的具体详情如下:
包路径:org.apache.poi.openxml4j.opc.internal.ZipHelper
类名称:ZipHelper
暂无
代码示例来源:origin: org.apache.poi/poi-ooxml
@Override
public boolean marshall(PackagePart part, OutputStream out)
throws OpenXML4JException {
if (!(out instanceof ZipArchiveOutputStream)) {
throw new IllegalArgumentException("ZipOutputStream expected!");
}
ZipArchiveOutputStream zos = (ZipArchiveOutputStream) out;
// Saving the part in the zip file
ZipArchiveEntry ctEntry = new ZipArchiveEntry(ZipHelper
.getZipItemNameFromOPCName(part.getPartName().getURI()
.toString()));
try {
// Save in ZIP
zos.putArchiveEntry(ctEntry); // Add entry in ZIP
try {
super.marshall(part, out); // Marshall the properties inside a XML
// Document
return StreamHelper.saveXmlInStream(xmlDoc, out);
} finally {
zos.closeArchiveEntry();
}
} catch (IOException e) {
throw new OpenXML4JException(e.getLocalizedMessage(), e);
}
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Retrieve and open as a secure zip file with the specified path.
*
* @param path
* The file path.
* @return The zip archive freshly open.
*/
public static ZipSecureFile openZipFile(String path) throws IOException {
return openZipFile(new File(path));
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
EntryTriple(final ZipArchiveEntry zipArchiveEntry, final ContentTypeManager contentTypeManager) {
this.zipArchiveEntry = zipArchiveEntry;
final String entryName = zipArchiveEntry.getName();
PackagePartName ppn = null;
try {
// We get an error when we parse [Content_Types].xml
// because it's not a valid URI.
ppn = (CONTENT_TYPES_PART_NAME.equalsIgnoreCase(entryName)) ? null
: PackagingURIHelper.createPartName(ZipHelper.getOPCNameFromZipItemName(entryName));
} catch (Exception e) {
// We assume we can continue, even in degraded mode ...
LOG.log(POILogger.WARN,"Entry " + entryName + " is not valid, so this part won't be add to the package.", e);
}
this.partName = ppn;
this.contentType = (ppn == null) ? null : contentTypeManager.getContentType(partName);
}
代码示例来源:origin: org.apache.poi/poi-ooxml
.getCorePropertiesZipEntry((ZipPackage) context
.getPackage());
in = ((ZipPackage) context.getPackage()).getZipArchive()
代码示例来源:origin: org.apache.poi/poi-ooxml
ZipArchiveEntry ctEntry = new ZipArchiveEntry(ZipHelper.getZipURIFromOPCName(
relPartName.getURI().toASCIIString()).getPath());
try {
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Opens the specified file as a secure zip, or returns null if no
* such file exists
*
* @param file
* The file to open.
* @return The zip archive freshly open.
* @throws IOException if the zip file cannot be opened or closed to read the header signature
* @throws NotOfficeXmlFileException if stream does not start with zip header signature
*/
public static ZipSecureFile openZipFile(File file) throws IOException, NotOfficeXmlFileException {
if (!file.exists()) {
throw new FileNotFoundException("File does not exist");
}
if (file.isDirectory()) {
throw new IOException("File is a directory");
}
// Peek at the first few bytes to sanity check
try (FileInputStream input = new FileInputStream(file)) {
verifyZipHeader(input);
}
// Open as a proper zip file
return new ZipSecureFile(file);
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Constructor. Opens a Zip based Open XML document from
* an InputStream.
*
* @param in
* Zip input stream to load.
* @param access
* The package access mode.
* @throws IllegalArgumentException
* If the specified input stream not an instance of
* ZipInputStream.
* @throws IOException
* if input stream cannot be opened, read, or closed
*/
ZipPackage(InputStream in, PackageAccess access) throws IOException {
super(access);
ZipArchiveThresholdInputStream zis = ZipHelper.openZipStream(in); // NOSONAR
try {
this.zipArchive = new ZipInputStreamZipEntrySource(zis);
} catch (final IOException e) {
IOUtils.closeQuietly(zis);
throw e;
}
}
代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev
.getCorePropertiesZipEntry((ZipPackage) context
.getPackage());
in = ((ZipPackage) context.getPackage()).getZipArchive()
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
ZipArchiveEntry ctEntry = new ZipArchiveEntry(ZipHelper.getZipURIFromOPCName(
relPartName.getURI().toASCIIString()).getPath());
try {
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Opens the specified stream as a secure zip
*
* @param stream
* The stream to open.
* @return The zip stream freshly open.
*/
@SuppressWarnings("resource")
public static ZipArchiveThresholdInputStream openZipStream(InputStream stream) throws IOException {
// Peek at the first few bytes to sanity check
InputStream checkedStream = FileMagic.prepareToCheckMagic(stream);
verifyZipHeader(checkedStream);
// Open as a proper zip stream
return new ZipArchiveThresholdInputStream(new ZipArchiveInputStream(checkedStream));
}
代码示例来源:origin: org.apache.poi/poi-ooxml
private static ZipEntrySource openZipEntrySourceStream(FileInputStream fis) throws InvalidOperationException {
final ZipArchiveThresholdInputStream zis;
// Acquire a resource that is needed to read the next level of openZipEntrySourceStream
try {
// open the zip input stream
zis = ZipHelper.openZipStream(fis); // NOSONAR
} catch (final IOException e) {
// If the source cannot be acquired, abort (no resources to free at this level)
throw new InvalidOperationException("Could not open the file input stream", e);
}
// If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource
try {
// read from the zip input stream
return openZipEntrySourceStream(zis);
} catch (final InvalidOperationException|UnsupportedFileFormatException e) {
// abort: close the zip input stream
IOUtils.closeQuietly(zis);
throw e;
} catch (final Exception e) {
// abort: close the zip input stream
IOUtils.closeQuietly(zis);
throw new InvalidOperationException("Failed to read the zip entry source stream", e);
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
.getZipItemNameFromOPCName(part.getPartName().getURI()
.getPath()));
try {
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Constructor. Opens a Zip based Open XML document from a File.
*
* @param file
* The file to open or create.
* @param access
* The package access mode.
* @throws InvalidOperationException If the zip file cannot be opened.
*/
ZipPackage(File file, PackageAccess access) throws InvalidOperationException {
super(access);
ZipEntrySource ze;
try {
final ZipFile zipFile = ZipHelper.openZipFile(file); // NOSONAR
ze = new ZipFileZipEntrySource(zipFile);
} catch (IOException e) {
// probably not happening with write access - not sure how to handle the default read-write access ...
if (access == PackageAccess.WRITE) {
throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e);
}
if ("java.util.zip.ZipException: archive is not a ZIP archive".equals(e.getMessage())) {
throw new NotOfficeXmlFileException("archive is not a ZIP archive", e);
}
LOG.log(POILogger.ERROR, "Error in zip file "+file+" - falling back to stream processing (i.e. ignoring zip central directory)");
ze = openZipEntrySourceStream(file);
}
this.zipArchive = ze;
}
代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev
/**
* Builds a PackagePartName for the given ZipEntry,
* or null if it's the content types / invalid part
*/
private PackagePartName buildPartName(ZipEntry entry) {
try {
// We get an error when we parse [Content_Types].xml
// because it's not a valid URI.
if (entry.getName().equalsIgnoreCase(
ContentTypeManager.CONTENT_TYPES_PART_NAME)) {
return null;
}
return PackagingURIHelper.createPartName(ZipHelper
.getOPCNameFromZipItemName(entry.getName()));
} catch (Exception e) {
// We assume we can continue, even in degraded mode ...
logger.log(POILogger.WARN,"Entry "
+ entry.getName()
+ " is not valid, so this part won't be add to the package.", e);
return null;
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
.getCorePropertiesZipEntry((ZipPackage) context
.getPackage());
in = ((ZipPackage) context.getPackage()).getZipArchive()
代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev
ZipEntry ctEntry = new ZipEntry(ZipHelper.getZipURIFromOPCName(
relPartName.getURI().toASCIIString()).getPath());
try {
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
/**
* Opens the specified file as a secure zip, or returns null if no
* such file exists
*
* @param file
* The file to open.
* @return The zip archive freshly open.
* @throws IOException if the zip file cannot be opened or closed to read the header signature
* @throws NotOfficeXmlFileException if stream does not start with zip header signature
*/
public static ZipSecureFile openZipFile(File file) throws IOException, NotOfficeXmlFileException {
if (!file.exists()) {
throw new FileNotFoundException("File does not exist");
}
if (file.isDirectory()) {
throw new IOException("File is a directory");
}
// Peek at the first few bytes to sanity check
try (FileInputStream input = new FileInputStream(file)) {
verifyZipHeader(input);
}
// Open as a proper zip file
return new ZipSecureFile(file);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
/**
* Constructor. Opens a Zip based Open XML document from
* an InputStream.
*
* @param in
* Zip input stream to load.
* @param access
* The package access mode.
* @throws IllegalArgumentException
* If the specified input stream not an instance of
* ZipInputStream.
* @throws IOException
* if input stream cannot be opened, read, or closed
*/
ZipPackage(InputStream in, PackageAccess access) throws IOException {
super(access);
ZipArchiveThresholdInputStream zis = ZipHelper.openZipStream(in); // NOSONAR
try {
this.zipArchive = new ZipInputStreamZipEntrySource(zis);
} catch (final IOException e) {
IOUtils.closeQuietly(zis);
throw e;
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
LOG.log(POILogger.DEBUG,"Save part '" + ZipHelper.getZipItemNameFromOPCName(ppn.getName()) + "'");
final PartMarshaller marshaller = partMarshallers.get(part._contentType);
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
/**
* Retrieve and open as a secure zip file with the specified path.
*
* @param path
* The file path.
* @return The zip archive freshly open.
*/
public static ZipSecureFile openZipFile(String path) throws IOException {
return openZipFile(new File(path));
}
}
内容来源于网络,如有侵权,请联系作者删除!