List of usage examples for java.util.zip ZipException toString
public String toString()
From source file:CrossRef.java
/** For each Zip file, for each entry, xref it */ public void processOneZip(String fileName) throws IOException { List entries = new ArrayList(); ZipFile zipFile = null;//from www. j a v a 2s .com try { zipFile = new ZipFile(new File(fileName)); } catch (ZipException zz) { throw new FileNotFoundException(zz.toString() + fileName); } Enumeration all = zipFile.entries(); // Put the entries into the List for sorting... while (all.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry) all.nextElement(); entries.add(zipEntry); } // Sort the entries (by class name) // Collections.sort(entries); // Process all the entries in this zip. Iterator it = entries.iterator(); while (it.hasNext()) { ZipEntry zipEntry = (ZipEntry) it.next(); String zipName = zipEntry.getName(); // Ignore package/directory, other odd-ball stuff. if (zipEntry.isDirectory()) { continue; } // Ignore META-INF stuff if (zipName.startsWith("META-INF/")) { continue; } // Ignore images, HTML, whatever else we find. if (!zipName.endsWith(".class")) { continue; } // If doing CLASSPATH, Ignore com.* which are "internal API". // if (doingStandardClasses && !zipName.startsWith("java")){ // continue; // } // Convert the zip file entry name, like // java/lang/Math.class // to a class name like // java.lang.Math String className = zipName.replace('/', '.').substring(0, zipName.length() - 6); // 6 for ".class" // Now get the Class object for it. Class c = null; try { c = Class.forName(className); } catch (ClassNotFoundException ex) { System.err.println("Error: " + ex); } // Hand it off to the subclass... doClass(c); } }
From source file:org.hammurapi.TaskBase.java
protected File processArchive() { if (archive == null) { return null; }/*from w ww. j a v a2 s . co m*/ String tmpDirProperty = System.getProperty("java.io.tmpdir"); File tmpDir = tmpDirProperty == null ? new File(".") : new File(tmpDirProperty); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); String prefix = "har_" + sdf.format(new Date()); File workDir = unpackDir == null ? new File(tmpDir, prefix) : unpackDir; for (int i = 0; unpackDir == null && workDir.exists(); i++) { workDir = new File(tmpDir, prefix + "_" + Integer.toString(i, Character.MAX_RADIX)); } if (workDir.exists() || workDir.mkdir()) { try { ZipFile zipFile = new ZipFile(archive); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (!entry.getName().endsWith("/")) { File outFile = new File(workDir, entry.getName().replace('/', File.separatorChar)); if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) { throw new BuildException("Directory does not exist and cannot be created: " + outFile.getParentFile().getAbsolutePath()); } log("Archive entry " + entry.getName() + " unpacked to " + outFile.getAbsolutePath(), Project.MSG_DEBUG); byte[] buf = new byte[4096]; int l; InputStream in = zipFile.getInputStream(entry); FileOutputStream fos = new FileOutputStream(outFile); while ((l = in.read(buf)) != -1) { fos.write(buf, 0, l); } in.close(); fos.close(); } } zipFile.close(); File configFile = new File(workDir, "config.xml"); if (configFile.exists() && configFile.isFile()) { Document configDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(configFile); processConfig(workDir, configDoc.getDocumentElement()); } else { throw new BuildException("Archive configuration file does not exist or is not a file"); } } catch (ZipException e) { throw new BuildException(e.toString(), e); } catch (IOException e) { throw new BuildException(e.toString(), e); } catch (SAXException e) { throw new BuildException(e.toString(), e); } catch (ParserConfigurationException e) { throw new BuildException(e.toString(), e); } catch (FactoryConfigurationError e) { throw new BuildException(e.toString(), e); } } else { throw new BuildException("Could not create directory " + workDir.getAbsolutePath()); } return unpackDir == null ? workDir : null; }
From source file:org.lockss.remote.RemoteApi.java
public BatchAuStatus processSavedConfigZip(InputStream configBackupStream) throws IOException, InvalidAuConfigBackupFile { // XXX This temp dir doesn't get deleted. It needs to stay around // through the entire multi-step restore interaction, so it's not clear // where to delete it. Not a big problem because it's only created if // the user does a restore.. File dir = FileUtil.createTempDir("locksscfg", ""); try {// ww w . ja v a 2 s.c o m ZipUtil.unzip(configBackupStream, dir); // Restore any subscriptions from the zip file. SubscriptionManager subMgr = getDaemon().getSubscriptionManager(); if (subMgr != null && subMgr.isReady()) { subMgr.loadSubscriptionsFromBackup(dir); } File autxt = new File(dir, ConfigManager.CONFIG_FILE_AU_CONFIG); if (!autxt.exists()) { throw new InvalidAuConfigBackupFile( "Uploaded file does not appear to be a saved AU configuration: no au.txt"); } BufferedInputStream auin = new BufferedInputStream(new FileInputStream(autxt)); try { BatchAuStatus bas = processSavedConfigProps(auin); bas.setBackupInfo(buildBackupInfo(dir)); if (log.isDebug3()) { log.debug3("processSavedConfigZip: " + bas); } return bas; } finally { IOUtil.safeClose(auin); } } catch (ZipException e) { FileUtil.delTree(dir); throw new InvalidAuConfigBackupFile( "Uploaded file does not appear to be a saved AU configuration: " + e.toString()); } catch (IOException e) { FileUtil.delTree(dir); throw e; } }