本文整理了Java中de.schlichtherle.truezip.zip.ZipFile
类的一些代码示例,展示了ZipFile
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipFile
类的具体详情如下:
包路径:de.schlichtherle.truezip.zip.ZipFile
类名称:ZipFile
[英]Drop-in replacement for java.util.zip.ZipFile.
Where the constructors of this class accept a charsetparameter, this is used to decode comments and entry names in the ZIP file. However, if an entry has bit 11 set in its General Purpose Bit Flag, then this parameter is ignored and "UTF-8" is used for this entry. This is in accordance to Appendix D of PKWARE's ZIP File Format Specification, version 6.3.0 and later.
This class is able to skip a preamble like the one found in self extracting archives.
Note that the entries returned by this class are instances of de.schlichtherle.truezip.io.zip.ZipEntry instead of java.util.zip.ZipEntry.
This class is thread-safe.
[中]作为java的替代品。util。拉链ZipFile。
如果此类的构造函数接受charsetparameter,则该参数用于解码ZIP文件中的注释和条目名称。但是,如果一个条目在其通用位标志中设置了位11,则该参数将被忽略,并将“UTF-8”用于该条目。这符合PKWARE ZIP文件格式规范6.3.0及更高版本的附录D。
这个类可以跳过自解压档案中的序言。
请注意,此类返回的条目是de.schlichtherle的实例。特鲁齐普。伊奥。拉链ZipEntry而不是java。util。拉链齐彭特里。
这个类是线程安全的。
代码示例来源:origin: org.apache.maven.indexer/indexer-core
public TrueZipZipFileHandle( final File targetFile )
throws IOException
{
super( targetFile );
this.zipFile = new ZipFile( targetFile );
}
代码示例来源:origin: org.apache.maven.indexer/indexer-core
public void close()
throws IOException
{
getZipFile().close();
}
代码示例来源:origin: apache/maven-indexer
public InputStream getEntryContent( String path )
throws IOException
{
ZipEntry entry = getZipFile().getEntry( path );
if ( entry != null )
{
return getZipFile().getInputStream( entry );
}
else
{
return null;
}
}
代码示例来源:origin: uk.gov.nationalarchives/droid-results
ZipFile zip = new ZipFile(source);
for (Enumeration<? extends ZipEntry> it = zip.entries(); it
.hasMoreElements();) {
ZipEntry e = it.nextElement();
for (Enumeration<? extends ZipEntry> it = zip.entries(); it
.hasMoreElements();) {
ZipEntry entry = it.nextElement();
.getInputStream(entry));
zip.close();
代码示例来源:origin: digital-preservation/droid
@Override
public void process(IdentificationRequest request, ContainerSignatureMatchCollection matches) throws IOException {
ZipFile zipFile = new ZipFile(new TrueZipReader(request.getWindowReader()), ZipFile.DEFAULT_CHARSET, true, false);
try {
final ZipEntry entry = zipFile.getEntry(entryName);
if (entry != null) {
InputStream stream = zipFile.getInputStream(entry);
ByteReader reader = null;
try {
zipFile.close();
代码示例来源:origin: de.schlichtherle.truezip/truezip-driver-zip
assertEquals(ZIP_SIZE, buffer.getSize(Size.STORAGE));
final ZipFile zf = new ZipFile(
buffer.getInputSocket().newReadOnlyFile());
try {
final byte[] buf = new byte[data.length];
for ( final Enumeration<? extends ZipEntry> e = zf.entries();
e.hasMoreElements(); ) {
final ZipEntry entry = e.nextElement();
final InputStream in = zf.getCheckedInputStream(entry);
try {
int off = 0;
zf.close();
代码示例来源:origin: de.schlichtherle.truezip/truezip-driver-zip
assertEquals(30, zipIn.size());
try {
for (int i = 0; i < 30; i++) {
final String name = i + ".txt";
final ZipEntry entry = zipIn.getEntry(name);
assertEquals(data1.length, entry.getSize());
final InputStream in = zipIn.getInputStream(name);
try {
int off = 0;
zipIn.close();
代码示例来源:origin: de.schlichtherle.truezip/truezip-driver-zip
@Override
protected ZipFile newZipFile(String name)
throws IOException {
ZipFile res = new ZipFile(name);
res.setCryptoParameters(new WinZipAesCryptoParameters());
return res;
}
代码示例来源:origin: uk.gov.nationalarchives/droid-core-interfaces
/**
* {@inheritDoc}
*/
@Override
public void handle(IdentificationRequest request) throws IOException {
final ZipFile zipFile = new ZipFile(new ReaderReadOnlyFile(request.getWindowReader()));
try {
Iterable<ZipEntry> iterable = new Iterable<ZipEntry>() {
@Override
public final Iterator<ZipEntry> iterator() {
return new ZipFileIterator(zipFile);
}
};
ZipArchiveWalker walker = new ZipArchiveWalker(request.getIdentifier(), zipFile);
walker.walk(iterable);
} finally {
if (zipFile != null) {
zipFile.close();
}
}
}
代码示例来源:origin: de.schlichtherle.truezip/truezip-driver-zip
final ZipFile zipIn = new ZipFile(file); // NOT newZipFile(...) !
InputStream in = zipIn.getCheckedInputStream(name);
if (tweakDD ^ tweakCFH)
fail("Expected CRC32Exception!");
InputStream in = zipIn.getCheckedInputStream(name);
if (tweakDD ^ tweakCFH)
fail("Expected CRC32Exception!");
zipIn.close();
代码示例来源:origin: de.schlichtherle.truezip/truezip-driver-zip
@Test
public final void testGetInputStream() throws IOException {
final ZipOutputStream zipOut
= newZipOutputStream(new FileOutputStream(file));
try {
zipOut.putNextEntry(newEntry("foo"));
} finally {
zipOut.close();
}
final ZipFile zipIn = newZipFile(file);
try {
zipIn.getInputStream("foo").close();
assertNull(zipIn.getInputStream("bar"));
} finally {
zipIn.close();
}
}
代码示例来源:origin: de.schlichtherle.truezip/truezip-driver-zip
@Test
public final void testPreambleOfEmptyZipFile() throws IOException {
// Create empty ZIP file.
newZipOutputStream(new FileOutputStream(file)).close();
// Assert that the empty ZIP file has no preamble.
final ZipFile zipIn = newZipFile(file);
try {
assertEquals(0, zipIn.getPreambleLength());
final InputStream in = zipIn.getPreambleInputStream();
try {
assertEquals(-1, in.read());
} finally {
in.close();
}
} finally {
zipIn.close();
}
}
代码示例来源:origin: uk.gov.nationalarchives/droid-core-interfaces
public ZipFileIterator(ZipFile fileToIterate) {
entries = fileToIterate.entries();
}
代码示例来源:origin: de.schlichtherle.truezip/truezip-driver-zip
@Test
public final void testGoodGetCheckedInputStream() throws IOException {
// Create test ZIP file.
final String name = "entry";
final ZipOutputStream zipOut
= newZipOutputStream(new FileOutputStream(file));
zipOut.putNextEntry(newEntry(name));
zipOut.write(data);
zipOut.close();
final ZipFile zipIn = newZipFile(file);
// Open checked input stream and join immediately.
InputStream in = zipIn.getCheckedInputStream(name);
in.close();
// Open checked input stream and read fully, using multiple methods.
in = zipIn.getCheckedInputStream(name);
final int n = data.length / 4;
in.skip(n);
in.read(new byte[n]);
in.read(new byte[n], 0, n);
while (in.read() != -1) { // read until EOF
}
in.close();
zipIn.close();
}
代码示例来源:origin: uk.gov.nationalarchives/droid-core-interfaces
InputStream in = null;
try {
in = file.getInputStream(entry);
request.open(in);
} finally {
代码示例来源:origin: apache/maven-indexer
public boolean hasEntry( String path )
throws IOException
{
return getZipFile().getEntry( path ) != null;
}
代码示例来源:origin: digital-preservation/droid
final ZipFile zip = new ZipFile(source.toFile());
for (final Enumeration<? extends ZipEntry> it = zip.entries(); it
.hasMoreElements();) {
ZipEntry e = it.nextElement();
for (final Enumeration<? extends ZipEntry> it = zip.entries(); it
.hasMoreElements();) {
ZipEntry entry = it.nextElement();
try (final InputStream in = new BufferedInputStream(zip.getInputStream(entry));
final OutputStream out = new BufferedOutputStream(Files.newOutputStream(expandedFile))) {
bytesSoFar = readFile(in, out, observer, bytesSoFar, totalSize);
zip.close();
代码示例来源:origin: uk.gov.nationalarchives/droid-container
@Override
public void process(IdentificationRequest request, ContainerSignatureMatchCollection matches) throws IOException {
ZipFile zipFile = new ZipFile(new ReaderReadOnlyFile(request.getWindowReader()), ZipFile.DEFAULT_CHARSET, true, false);
try {
final ZipEntry entry = zipFile.getEntry(entryName);
if (entry != null) {
InputStream stream = zipFile.getInputStream(entry);
ByteReader reader = null;
try {
zipFile.close();
代码示例来源:origin: de.schlichtherle.truezip/truezip-driver-zip
@Override
protected ZipFile newZipFile(
File file, Charset charset)
throws IOException {
ZipFile res = new ZipFile(file, charset);
res.setCryptoParameters(new WinZipAesCryptoParameters());
return res;
}
代码示例来源:origin: digital-preservation/droid
/**
* {@inheritDoc}
*/
@Override
public void handle(IdentificationRequest request) throws IOException {
final ZipFile zipFile = new ZipFile(new TrueZipReader(request.getWindowReader()));
try {
Iterable<ZipEntry> iterable = new Iterable<ZipEntry>() {
@Override
public final Iterator<ZipEntry> iterator() {
return new ZipFileIterator(zipFile);
}
};
ZipArchiveWalker walker = new ZipArchiveWalker(request.getIdentifier(), zipFile);
walker.walk(iterable);
} finally {
if (zipFile != null) {
zipFile.close();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!