mirror of https://github.com/apache/poi.git
reformat ZipFileZipEntrySource.java
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1918799 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
527f26aac9
commit
d879a94a15
|
@ -26,61 +26,62 @@ import org.apache.commons.compress.archivers.zip.ZipFile;
|
||||||
/**
|
/**
|
||||||
* A ZipEntrySource wrapper around a ZipFile.
|
* A ZipEntrySource wrapper around a ZipFile.
|
||||||
* Should be as low in terms of memory as a
|
* Should be as low in terms of memory as a
|
||||||
* normal ZipFile implementation is.
|
* normal ZipFile implementation is.
|
||||||
*/
|
*/
|
||||||
public class ZipFileZipEntrySource implements ZipEntrySource {
|
public class ZipFileZipEntrySource implements ZipEntrySource {
|
||||||
private ZipFile zipArchive;
|
private ZipFile zipArchive;
|
||||||
public ZipFileZipEntrySource(ZipFile zipFile) {
|
|
||||||
this.zipArchive = zipFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public ZipFileZipEntrySource(ZipFile zipFile) {
|
||||||
public void close() throws IOException {
|
this.zipArchive = zipFile;
|
||||||
if(zipArchive != null) {
|
}
|
||||||
zipArchive.close();
|
|
||||||
}
|
|
||||||
zipArchive = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClosed() {
|
public void close() throws IOException {
|
||||||
return (zipArchive == null);
|
if (zipArchive != null) {
|
||||||
}
|
zipArchive.close();
|
||||||
|
}
|
||||||
|
zipArchive = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Enumeration<? extends ZipArchiveEntry> getEntries() {
|
public boolean isClosed() {
|
||||||
if (zipArchive == null)
|
return (zipArchive == null);
|
||||||
throw new IllegalStateException("Zip File is closed");
|
}
|
||||||
|
|
||||||
return zipArchive.getEntries();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInputStream(ZipArchiveEntry entry) throws IOException {
|
public Enumeration<? extends ZipArchiveEntry> getEntries() {
|
||||||
if (zipArchive == null)
|
if (zipArchive == null)
|
||||||
throw new IllegalStateException("Zip File is closed");
|
throw new IllegalStateException("Zip File is closed");
|
||||||
|
|
||||||
return zipArchive.getInputStream(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return zipArchive.getEntries();
|
||||||
public ZipArchiveEntry getEntry(final String path) {
|
}
|
||||||
String normalizedPath = path.replace('\\', '/');
|
|
||||||
|
|
||||||
final ZipArchiveEntry entry = zipArchive.getEntry(normalizedPath);
|
@Override
|
||||||
if (entry != null) {
|
public InputStream getInputStream(ZipArchiveEntry entry) throws IOException {
|
||||||
return entry;
|
if (zipArchive == null)
|
||||||
}
|
throw new IllegalStateException("Zip File is closed");
|
||||||
|
|
||||||
// the opc spec allows case-insensitive filename matching (see #49609)
|
return zipArchive.getInputStream(entry);
|
||||||
final Enumeration<ZipArchiveEntry> zipArchiveEntryEnumeration = zipArchive.getEntries();
|
}
|
||||||
while (zipArchiveEntryEnumeration.hasMoreElements()) {
|
|
||||||
ZipArchiveEntry ze = zipArchiveEntryEnumeration.nextElement();
|
|
||||||
if (normalizedPath.equalsIgnoreCase(ze.getName().replace('\\','/'))) {
|
|
||||||
return ze;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
@Override
|
||||||
}
|
public ZipArchiveEntry getEntry(final String path) {
|
||||||
|
String normalizedPath = path.replace('\\', '/');
|
||||||
|
|
||||||
|
final ZipArchiveEntry entry = zipArchive.getEntry(normalizedPath);
|
||||||
|
if (entry != null) {
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the opc spec allows case-insensitive filename matching (see #49609)
|
||||||
|
final Enumeration<ZipArchiveEntry> zipArchiveEntryEnumeration = zipArchive.getEntries();
|
||||||
|
while (zipArchiveEntryEnumeration.hasMoreElements()) {
|
||||||
|
ZipArchiveEntry ze = zipArchiveEntryEnumeration.nextElement();
|
||||||
|
if (normalizedPath.equalsIgnoreCase(ze.getName().replace('\\', '/'))) {
|
||||||
|
return ze;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue