/* * Copyright (c) 2013 Google Inc. 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.
*/
try (FileOutputStream fos = new FileOutputStream(zipFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
ZipOutputStream zos = new ZipOutputStream(bos)) {
// Add entries to allow the zip file to be used with "java -jar"
zos.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF")); for (String line : new String[] { "Manifest-Version: 1.0", "Main-Class: " + MAIN_CLASS,
})
zos.write((line + "\n").getBytes("US-ASCII"));
zos.closeEntry();
String testClasses = System.getProperty("test.classes"); for (String className : SPECIAL_CLASSES) {
String baseName = className + ".class";
ZipEntry ze = new ZipEntry(baseName);
File file = new File(testClasses, baseName);
zos.putNextEntry(ze);
Files.copy(file.toPath(), zos);
zos.closeEntry();
}
for (int i = SPECIAL_COUNT; i < entryCount; i++) {
zos.putNextEntry(new ZipEntry(Integer.toString(i)));
zos.closeEntry();
}
}
staticboolean usesZip64(File zipFile) throws Exception {
RandomAccessFile raf = new RandomAccessFile(zipFile, "r"); byte[] buf = newbyte[4096];
raf.seek(raf.length() - buf.length);
raf.read(buf); for (int i = 0; i < buf.length - 4; i++) { // Look for ZIP64 End Header Signature // Phil Katz: yes, we will always remember you if (buf[i+0] == 'P' &&
buf[i+1] == 'K' &&
buf[i+2] == 6 &&
buf[i+3] == 6) returntrue;
} returnfalse;
}
staticvoid checkCanRead(File zipFile, int entryCount) throws Throwable { // Check ZipInputStream API try (FileInputStream fis = new FileInputStream(zipFile);
BufferedInputStream bis = new BufferedInputStream(fis);
ZipInputStream zis = new ZipInputStream(bis)) { for (int i = 0; i < entryCount; i++) {
ZipEntry e = zis.getNextEntry(); if (i >= SPECIAL_COUNT) // skip special entries if (Integer.parseInt(e.getName()) != i) thrownew AssertionError(e.getName());
} if (zis.getNextEntry() != null) thrownew AssertionError();
}
// Check ZipFile API try (ZipFile zf = new ZipFile(zipFile)) {
Enumeration<? extends ZipEntry> en = zf.entries(); for (int i = 0; i < entryCount; i++) {
ZipEntry e = en.nextElement(); if (i >= SPECIAL_COUNT) // skip special entries if (Integer.parseInt(e.getName()) != i) thrownew AssertionError();
} if (en.hasMoreElements()
|| (zf.size() != entryCount)
|| (zf.getEntry(Integer.toString(entryCount - 1)) == null)
|| (zf.getEntry(Integer.toString(entryCount)) != null)) thrownew AssertionError();
}
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 und die Messung sind noch experimentell.