/* * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* @test * @bug 4770745 6234507 6303183 8048990 * @summary test a variety of zip file entries * @author Martin Buchholz * @key randomness
*/
// check if all "expected" extra fields equal to their // corresponding fields in "extra". The "extra" might have // timestamp fields added by ZOS. staticboolean equalsExtraData(byte[] expected, byte[] extra) { if (expected == null) returntrue; int off = 0; int len = expected.length; while (off + 4 < len) { int tag = get16(expected, off); int sz = get16(expected, off + 2); int off0 = 0; int len0 = extra.length; boolean matched = false; while (off0 + 4 < len0) { int tag0 = get16(extra, off0); int sz0 = get16(extra, off0 + 2); if (tag == tag0 && sz == sz0) {
matched = true; for (int i = 0; i < sz; i++) { if (expected[off + i] != extra[off0 +i])
matched = false;
} break;
}
off0 += (4 + sz0);
} if (!matched) returnfalse;
off += (4 + sz);
} returntrue;
}
// Highly unusual manifest
entries.add(new Entry("meta-iNf/ManIfEst.Mf",
ZipEntry.STORED,
toBytes("maNiFest-VeRsIon: 1.0\n"),
toExtra(toBytes("Can manifests have extra??")), "Can manifests have comments??"));
// The emptiest possible entry
entries.add(new Entry("", ZipEntry.STORED, null, null, ""));
for (String name : names) for (int method : methods) for (byte[] data : datas) // datae?? for (byte[] extra : extras) for (String comment : comments)
entries.add(new Entry(uniquify(name), method, data,
toExtra(extra), comment));
//---------------------------------------------------------------- // Write zip file using ZipOutputStream //---------------------------------------------------------------- try (FileOutputStream fos = new FileOutputStream(zipName);
ZipOutputStream zos = new ZipOutputStream(fos))
{ for (Entry e : entries)
e.write(zos);
}
//---------------------------------------------------------------- // Verify zip file contents using ZipFile.getEntry() //---------------------------------------------------------------- try (ZipFile f = new ZipFile(zipName)) { for (Entry e : entries)
e.verify(f);
}
//---------------------------------------------------------------- // Verify zip file contents using JarFile.getEntry() //---------------------------------------------------------------- try (JarFile f = new JarFile(zipName)) {
check(f.getManifest() != null); for (Entry e : entries)
e.verify(f);
}
//---------------------------------------------------------------- // Verify zip file contents using ZipFile.entries() //---------------------------------------------------------------- try (ZipFile f = new ZipFile(zipName)) {
Enumeration<? extends ZipEntry> en = f.entries(); for (Entry e : entries)
e.verify(f, en.nextElement());
check(!en.hasMoreElements());
}
//---------------------------------------------------------------- // Verify zip file contents using JarFile.entries() //---------------------------------------------------------------- try (JarFile f = new JarFile(zipName)) {
Enumeration<? extends ZipEntry> en = f.entries(); for (Entry e : entries)
e.verify(f, en.nextElement());
check(!en.hasMoreElements());
}
//---------------------------------------------------------------- // Verify zip file contents using ZipInputStream class //---------------------------------------------------------------- try (FileInputStream fis = new FileInputStream(zipName);
ZipInputStream s = new ZipInputStream(fis)) {
for (Entry e : entries)
e.verifyZipInputStream(s);
}
//---------------------------------------------------------------- // Verify zip file contents using JarInputStream class //---------------------------------------------------------------- try (FileInputStream fis = new FileInputStream(zipName);
JarInputStream s = new JarInputStream(fis)) {
// JarInputStream "automatically" reads the manifest
check(s.getManifest() != null);
for (Entry e : entries)
e.verifyJarInputStream(s);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.