use of java.util.zip.ZipException in project robovm by robovm.
the class ZipFileTest method testDuplicateEntries.
/**
* Make sure we don't fail silently for duplicate entries.
* b/8219321
*/
public void testDuplicateEntries() throws Exception {
String name1 = "test_file_name1";
String name2 = "test_file_name2";
// Create the good zip file.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream out = new ZipOutputStream(baos);
out.putNextEntry(new ZipEntry(name2));
out.closeEntry();
out.putNextEntry(new ZipEntry(name1));
out.closeEntry();
out.close();
// Rewrite one of the filenames.
byte[] buffer = baos.toByteArray();
replaceBytes(buffer, name2.getBytes(), name1.getBytes());
// Write the result to a file.
File badZip = createTemporaryZipFile();
writeBytes(badZip, buffer);
// Check that we refuse to load the modified file.
try {
ZipFile bad = new ZipFile(badZip);
fail();
} catch (ZipException expected) {
}
}
use of java.util.zip.ZipException in project robovm by robovm.
the class OldZipExceptionTest method testZipException.
public void testZipException() {
ZipException zz = new ZipException();
assertEquals(zz.getMessage(), null);
}
use of java.util.zip.ZipException in project robovm by robovm.
the class OldZipInputStreamTest method test_closeEntry.
public void test_closeEntry() throws Exception {
zis.getNextEntry();
zis.closeEntry();
zis.getNextEntry();
zis.close();
try {
zis.closeEntry();
fail("IOException expected");
} catch (IOException ee) {
// expected
}
File resources = Support_Resources.createTempFolder();
Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
FileInputStream fis = new FileInputStream(new File(resources, "Broken_manifest.jar"));
ZipInputStream zis1 = new ZipInputStream(fis);
try {
for (int i = 0; i < 6; i++) {
zis1.getNextEntry();
zis1.closeEntry();
}
fail("ZipException expected");
} catch (ZipException ee) {
// expected
}
}
use of java.util.zip.ZipException in project robovm by robovm.
the class JarFileTest method test_getInputStreamLjava_util_jar_JarEntry.
/**
* @throws IOException
* java.util.jar.JarFile#getInputStream(java.util.zip.ZipEntry)
*/
public void test_getInputStreamLjava_util_jar_JarEntry() throws IOException {
File localFile = null;
try {
Support_Resources.copyFile(resources, null, jarName);
localFile = new File(resources, jarName);
} catch (Exception e) {
fail("Failed to create local file: " + e);
}
byte[] b = new byte[1024];
try {
JarFile jf = new JarFile(localFile);
java.io.InputStream is = jf.getInputStream(jf.getEntry(entryName));
// BEGIN android-removed
// jf.close();
// END android-removed
assertTrue("Returned invalid stream", is.available() > 0);
int r = is.read(b, 0, 1024);
is.close();
StringBuffer sb = new StringBuffer(r);
for (int i = 0; i < r; i++) {
sb.append((char) (b[i] & 0xff));
}
String contents = sb.toString();
assertTrue("Incorrect stream read", contents.indexOf("bar") > 0);
// BEGIN android-added
jf.close();
// END android-added
} catch (Exception e) {
fail("Exception during test: " + e.toString());
}
try {
JarFile jf = new JarFile(localFile);
InputStream in = jf.getInputStream(new JarEntry("invalid"));
assertNull("Got stream for non-existent entry", in);
} catch (Exception e) {
fail("Exception during test 2: " + e);
}
try {
Support_Resources.copyFile(resources, null, jarName);
File signedFile = new File(resources, jarName);
JarFile jf = new JarFile(signedFile);
JarEntry jre = new JarEntry("foo/bar/A.class");
jf.getInputStream(jre);
// InputStream returned in any way, exception can be thrown in case
// of reading from this stream only.
// fail("Should throw ZipException");
} catch (ZipException ee) {
// expected
}
try {
Support_Resources.copyFile(resources, null, jarName);
File signedFile = new File(resources, jarName);
JarFile jf = new JarFile(signedFile);
JarEntry jre = new JarEntry("foo/bar/A.class");
jf.close();
jf.getInputStream(jre);
// InputStream returned in any way, exception can be thrown in case
// of reading from this stream only.
// The same for IOException
fail("Should throw IllegalStateException");
} catch (IllegalStateException ee) {
// expected
}
}
use of java.util.zip.ZipException in project bazel by bazelbuild.
the class FdoSupport method extractFdoZip.
/**
* Extracts the FDO zip file and collects data from it that's needed during analysis.
*
* <p>When an {@code --fdo_optimize} compile is requested, unpacks the given
* FDO gcda zip file into a clean working directory under execRoot.
*
* @throws FdoException if the FDO ZIP contains a file of unknown type
*/
private static FdoZipContents extractFdoZip(FdoMode fdoMode, LipoMode lipoMode, Path execRoot, Path fdoProfile, PathFragment fdoRootExecPath, String productName) throws IOException, FdoException {
// The execRoot != null case is only there for testing. We cannot provide a real ZIP file in
// tests because ZipFileSystem does not work with a ZIP on an in-memory file system.
// IMPORTANT: Keep in sync with #declareSkyframeDependencies to avoid incrementality issues.
ImmutableSet<PathFragment> gcdaFiles = ImmutableSet.of();
ImmutableMultimap<PathFragment, PathFragment> imports = ImmutableMultimap.of();
if (fdoProfile != null && execRoot != null) {
Path fdoDirPath = execRoot.getRelative(fdoRootExecPath);
FileSystemUtils.deleteTreesBelow(fdoDirPath);
FileSystemUtils.createDirectoryAndParents(fdoDirPath);
if (fdoMode == FdoMode.AUTO_FDO) {
if (lipoMode != LipoMode.OFF) {
imports = readAutoFdoImports(getAutoFdoImportsPath(fdoProfile));
}
FileSystemUtils.ensureSymbolicLink(execRoot.getRelative(getAutoProfilePath(fdoProfile, fdoRootExecPath)), fdoProfile);
} else if (fdoMode == FdoMode.LLVM_FDO) {
FileSystemUtils.ensureSymbolicLink(execRoot.getRelative(getLLVMProfilePath(fdoProfile, fdoRootExecPath)), fdoProfile);
} else {
Path zipFilePath = new ZipFileSystem(fdoProfile).getRootDirectory();
String outputSymlinkName = productName + "-out";
if (!zipFilePath.getRelative(outputSymlinkName).isDirectory()) {
throw new ZipException("FDO zip files must be zipped directly above '" + outputSymlinkName + "' for the compiler to find the profile");
}
ImmutableSet.Builder<PathFragment> gcdaFilesBuilder = ImmutableSet.builder();
ImmutableMultimap.Builder<PathFragment, PathFragment> importsBuilder = ImmutableMultimap.builder();
extractFdoZipDirectory(zipFilePath, fdoDirPath, gcdaFilesBuilder, importsBuilder);
gcdaFiles = gcdaFilesBuilder.build();
imports = importsBuilder.build();
}
}
return new FdoZipContents(gcdaFiles, imports);
}
Aggregations