use of java.util.zip.ZipException in project j2objc by google.
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 j2objc by google.
the class OldZipInputStreamTest method test_read$BII.
public void test_read$BII() throws Exception {
byte[] rbuf;
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);
zis1.getNextEntry();
zis1.getNextEntry();
rbuf = new byte[100];
try {
zis1.read(rbuf, 10, 90);
fail("ZipException expected");
} catch (ZipException ee) {
// expected
}
try {
// Android throws exception here, already!
zis1.close();
// But RI here, only!
zis1.read(rbuf, 10, 90);
fail("IOException expected");
} catch (IOException ee) {
// expected
}
}
use of java.util.zip.ZipException in project j2objc by google.
the class JarInputStreamTest method test_closeAfterException.
public void test_closeAfterException() throws Exception {
File resources = Support_Resources.createTempFolder();
Support_Resources.copyFile(resources, null, "Broken_entry.jar");
InputStream is = Support_Resources.getStream("Broken_entry.jar");
JarInputStream jis = new JarInputStream(is, false);
jis.getNextEntry();
try {
jis.getNextEntry();
fail("ZipException expected");
} catch (ZipException ee) {
// expected
}
jis.close();
try {
jis.getNextEntry();
fail("IOException expected");
} catch (IOException ee) {
// expected
}
}
use of java.util.zip.ZipException in project j2objc by google.
the class GenerationBatch method processJarFile.
private void processJarFile(String filename) {
File f = findJarFile(filename);
if (f == null) {
ErrorUtil.error("No such file: " + filename);
return;
}
// don't support Java-like source paths.
if (options.emitLineDirectives() && options.isVerbose()) {
ErrorUtil.warning("source debugging of jar files is not supported: " + filename);
}
GenerationUnit combinedUnit = null;
if (globalCombinedUnit != null) {
combinedUnit = globalCombinedUnit;
} else if (options.getHeaderMap().combineSourceJars()) {
combinedUnit = GenerationUnit.newCombinedJarUnit(filename, options);
}
try {
ZipFile zfile = new ZipFile(f);
try {
boolean containsJavaFile = false;
Enumeration<? extends ZipEntry> enumerator = zfile.entries();
File tempDir = FileUtil.createTempDir(J2OBJC_TEMP_DIR_PREFIX);
String tempDirPath = tempDir.getAbsolutePath();
options.fileUtil().addTempDir(tempDirPath);
options.fileUtil().appendSourcePath(tempDirPath);
while (enumerator.hasMoreElements()) {
ZipEntry entry = enumerator.nextElement();
String internalPath = entry.getName();
if (internalPath.endsWith(".java") || (options.translateClassfiles() && internalPath.endsWith(".class"))) {
// Extract JAR file to a temporary directory
File outputFile = options.fileUtil().extractZipEntry(tempDir, zfile, entry);
InputFile newFile = new RegularInputFile(outputFile.getAbsolutePath(), internalPath);
if (combinedUnit != null) {
inputs.add(new ProcessingContext(newFile, combinedUnit));
} else {
addExtractedJarSource(newFile, filename, internalPath);
}
containsJavaFile = true;
}
}
if (!options.translateClassfiles() && !containsJavaFile) {
ErrorUtil.error(filename + " does not contain any Java source files.");
}
} finally {
// Also closes input stream.
zfile.close();
}
} catch (ZipException e) {
// Also catches JarExceptions
logger.fine(e.getMessage());
ErrorUtil.error("Error reading file " + filename + " as a zip or jar file.");
} catch (IOException e) {
ErrorUtil.error(e.getMessage());
}
}
use of java.util.zip.ZipException in project dhis2-core by dhis2.
the class JCloudsAppStorageService method installApp.
@Override
public App installApp(File file, String filename, Cache<App> appCache) {
App app = new App();
log.info("Installing new app: " + filename);
try (ZipFile zip = new ZipFile(file)) {
// -----------------------------------------------------------------
// Parse ZIP file and it's manifest.webapp file.
// -----------------------------------------------------------------
ZipEntry entry = zip.getEntry(MANIFEST_FILENAME);
if (entry == null) {
log.error("Failed to install app: Missing manifest.webapp in zip");
app.setAppState(AppStatus.MISSING_MANIFEST);
return app;
}
InputStream inputStream = zip.getInputStream(entry);
app = jsonMapper.readValue(inputStream, App.class);
app.setFolderName(APPS_DIR + File.separator + filename.substring(0, filename.lastIndexOf('.')));
app.setAppStorageSource(AppStorageSource.JCLOUDS);
if (!this.validateApp(app, appCache)) {
return app;
}
String namespace = app.getActivities().getDhis().getNamespace();
// -----------------------------------------------------------------
// Unzip the app
// -----------------------------------------------------------------
String dest = APPS_DIR + File.separator + filename.substring(0, filename.lastIndexOf('.'));
zip.stream().forEach((Consumer<ZipEntry>) zipEntry -> {
log.debug("Uploading zipEntry: " + zipEntry);
try {
InputStream input = zip.getInputStream(zipEntry);
Blob blob = blobStore.blobBuilder(dest + File.separator + zipEntry.getName()).payload(input).contentLength(zipEntry.getSize()).build();
blobStore.putBlob(config.container, blob);
input.close();
} catch (IOException e) {
log.error("Unable to store app file '" + zipEntry.getName() + "'", e);
}
});
log.info(String.format("" + "New app '%s' installed" + "\n\tInstall path: %s" + (namespace != null && !namespace.isEmpty() ? "\n\tNamespace reserved: %s" : ""), app.getName(), dest, namespace));
// -----------------------------------------------------------------
// Installation complete.
// -----------------------------------------------------------------
app.setAppState(AppStatus.OK);
return app;
} catch (ZipException e) {
log.error("Failed to install app: Invalid ZIP format", e);
app.setAppState(AppStatus.INVALID_ZIP_FORMAT);
} catch (JsonParseException e) {
log.error("Failed to install app: Invalid manifest.webapp", e);
app.setAppState(AppStatus.INVALID_MANIFEST_JSON);
} catch (IOException e) {
log.error("Failed to install app: Could not save app", e);
app.setAppState(AppStatus.INSTALLATION_FAILED);
}
return app;
}
Aggregations