List of usage examples for java.util.zip ZipException getMessage
public String getMessage()
From source file:asciidoc.maven.plugin.AbstractAsciiDocMojo.java
/** * No-arg constructor./*from w w w . java2 s. c om*/ */ public AbstractAsciiDocMojo() { try { File jarFile = new File(AbstractAsciiDocMojo.class.getProtectionDomain().getCodeSource().getLocation() .toURI().getPath()); if (getLog().isDebugEnabled()) getLog().debug("sourceJarFile: " + jarFile.getAbsolutePath()); if (asciiDocHome == null) { ZipEntry zipEntry = null; String zipEntryName = null; ZipFile jarZipFile = new ZipFile(jarFile); Enumeration<? extends ZipEntry> e = jarZipFile.entries(); while (e.hasMoreElements()) { zipEntry = (ZipEntry) e.nextElement(); zipEntryName = zipEntry.getName(); if (zipEntryName.startsWith("asciidoc") && zipEntryName.endsWith(".zip")) { if (getLog().isInfoEnabled()) getLog().info("Found AsciiDoc in " + zipEntryName); asciiDocHome = new File(jarFile.getParent(), FilenameUtils.removeExtension(zipEntryName)); break; } } if (asciiDocHome != null && !asciiDocHome.exists()) { unzipEntry(jarZipFile, zipEntry, jarFile.getParentFile()); File asciiDocArchive = new File(jarFile.getParent(), zipEntryName); unzipArchive(asciiDocArchive, jarFile.getParentFile()); asciiDocArchive.deleteOnExit(); } if (getLog().isInfoEnabled()) getLog().info("asciiDocHome: " + asciiDocHome); } } catch (URISyntaxException use) { getLog().error(use.getMessage(), use); // don't throw use; } catch (ZipException ze) { getLog().error(ze.getMessage(), ze); // don't throw ze; } catch (IOException ioe) { getLog().error(ioe.getMessage(), ioe); // don't throw ioe; } }
From source file:com.l2jfree.gameserver.script.faenor.FaenorScriptEngine.java
private void loadPackages() { File packDirectory = new File(Config.DATAPACK_ROOT, PACKAGE_DIRECTORY); FileFilter fileFilter = new FileFilter() { @Override//ww w.j a va 2s. c o m public boolean accept(File file) { return file.getName().endsWith(".zip"); } }; File[] files = packDirectory.listFiles(fileFilter); if (files == null) return; ZipFile zipPack; for (File element : files) { try { zipPack = new ZipFile(element); } catch (ZipException e) { _log.error(e.getMessage(), e); continue; } catch (IOException e) { _log.error(e.getMessage(), e); continue; } ScriptPackage module = new ScriptPackage(zipPack); List<ScriptDocument> scripts = module.getScriptFiles(); for (ScriptDocument script : scripts) { _scripts.add(script); } try { zipPack.close(); } catch (IOException e) { } } }
From source file:com.phonegap.plugin.files.ExtractZipFilePlugin.java
@Override public boolean execute(String action, JSONArray args, CallbackContext cbc) { PluginResult.Status status = PluginResult.Status.OK; try {/*from w w w.j ava 2s.c o m*/ String filename = args.getString(0); URL url; try { url = new URL(filename); } catch (MalformedURLException e) { throw new RuntimeException(e); } File file = new File(url.getFile()); String[] dirToSplit = url.getFile().split(File.separator); String dirToInsert = ""; for (int i = 0; i < dirToSplit.length - 1; i++) { dirToInsert += dirToSplit[i] + File.separator; } ZipEntry entry; ZipFile zipfile; try { zipfile = new ZipFile(file); Enumeration e = zipfile.entries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); BufferedInputStream is = null; try { is = new BufferedInputStream(zipfile.getInputStream(entry)); int count; byte data[] = new byte[102222]; String fileName = dirToInsert + entry.getName(); File outFile = new File(fileName); if (entry.isDirectory()) { if (!outFile.exists() && !outFile.mkdirs()) { Log.v("info", "Unable to create directories: " + outFile.getAbsolutePath()); cbc.sendPluginResult(new PluginResult(IO_EXCEPTION)); return false; } } else { File parent = outFile.getParentFile(); if (parent.mkdirs()) { Log.v("info", "created directory leading to file"); } FileOutputStream fos = null; BufferedOutputStream dest = null; try { fos = new FileOutputStream(outFile); dest = new BufferedOutputStream(fos, 102222); while ((count = is.read(data, 0, 102222)) != -1) { dest.write(data, 0, count); } } finally { if (dest != null) { dest.flush(); dest.close(); } if (fos != null) { fos.close(); } } } } finally { if (is != null) { is.close(); } } } } catch (ZipException e1) { Log.v("error", e1.getMessage(), e1); cbc.sendPluginResult(new PluginResult(MALFORMED_URL_EXCEPTION)); return false; } catch (IOException e1) { Log.v("error", e1.getMessage(), e1); cbc.sendPluginResult(new PluginResult(IO_EXCEPTION)); return false; } } catch (JSONException e) { cbc.sendPluginResult(new PluginResult(JSON_EXCEPTION)); return false; } cbc.sendPluginResult(new PluginResult(status)); return true; }
From source file:com.marklogic.contentpump.OutputArchive.java
public void write(String uri, InputStream is, long size) throws IOException { ZipEntry entry = new ZipEntry(uri); if (outputStream == null || (currentFileBytes + size > Integer.MAX_VALUE) && currentFileBytes > 0) { newOutputStream();/*from w ww . java 2 s .c o m*/ } try { outputStream.putNextEntry(entry); long bufSize = Math.min(size, 512 << 10); byte[] buf = new byte[(int) bufSize]; for (long toRead = size, read = 0; toRead > 0; toRead -= read) { read = is.read(buf, 0, (int) bufSize); if (read > 0) { outputStream.write(buf, 0, (int) read); } else { LOG.warn("Premature EOF: uri=" + uri + ",toRead=" + toRead); break; } } outputStream.closeEntry(); } catch (ZipException e) { LOG.warn("Exception caught: " + e.getMessage() + entry.getName()); } currentFileBytes += size; currentEntries++; }
From source file:com.marklogic.contentpump.OutputArchive.java
public long write(String outputPath, byte[] bytes) throws IOException { if (null == outputPath) { throw new NullPointerException("null path"); }/*from w w w.jav a 2 s . c o m*/ if (null == bytes) { throw new NullPointerException("null content bytes"); } long total = bytes.length; ZipEntry entry = new ZipEntry(outputPath); if (outputStream == null) { newOutputStream(); } if (currentFileBytes > 0 && currentFileBytes + total > Integer.MAX_VALUE) { if (currentEntries % 2 == 0) { //the file overflowed is metadata, create new zip newOutputStream(); } else { //the file overflowed is doc, keep it in current zip LOG.warn("too many bytes in current package:" + currPath); } } try { outputStream.putNextEntry(entry); outputStream.write(bytes); outputStream.closeEntry(); } catch (ZipException e) { LOG.warn("Exception caught: " + e.getMessage() + entry.getName()); return 0; } currentFileBytes += total; currentEntries++; return total; }
From source file:inventory.pl.services.BackupService.java
private void archive(File outputFile) { try {/*from w ww . jav a 2 s .c o m*/ byte[] buffer = new byte[1024]; File f; SevenZOutputFile sevenZOutput = new SevenZOutputFile(outputFile); System.out.println("Output to Zip : " + outputFile); long startTime = System.currentTimeMillis(); for (String file : this.entries) { f = new File(SOURCE_FOLDER + File.separator + file); System.out.println("File Added : " + f.getAbsolutePath()); SevenZArchiveEntry ze = sevenZOutput.createArchiveEntry(f, file); try { FileInputStream in = new FileInputStream(SOURCE_FOLDER + File.separator + file); sevenZOutput.putArchiveEntry(ze); int len; while ((len = in.read(buffer)) > 0) { sevenZOutput.write(buffer, 0, len); } sevenZOutput.closeArchiveEntry(); in.close(); } catch (java.util.zip.ZipException zipException) { System.err.println("ex=" + zipException.getMessage()); } } long endTime = System.currentTimeMillis(); sevenZOutput.close(); System.out.println("Done in " + (endTime - startTime)); } catch (IOException ex) { Logger.getLogger(BackupService.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.openflexo.foundation.cg.action.ImportDocumentationTemplates.java
/** * Overrides doAction//www. ja v a 2s . co m * * @see org.openflexo.foundation.action.FlexoAction#doAction(java.lang.Object) */ @Override protected void doAction(Object context) throws FlexoException { makeFlexoProgress("importing_documentation_templates", 2); try { File documentationTemplateDirectory = FileUtils.createTempDirectory("DocumentTemplates", ".tmp"); ZipUtils.unzip(zipFile, documentationTemplateDirectory, getFlexoProgress()); Collection<File> tocFiles = org.apache.commons.io.FileUtils.listFiles(documentationTemplateDirectory, new String[] { "toc.xml" }, true); makeFlexoProgress("importing_documentation_templates", tocFiles.size()); for (File tocfile : tocFiles) { importTemplatesFromDir(tocfile); } } catch (ZipException e) { e.printStackTrace(); throw new ImportException( FlexoLocalization.localizedForKey("invalid_zip_file") + " (" + e.getMessage() + ")", e); } catch (IOException e) { e.printStackTrace(); throw new ImportException( FlexoLocalization.localizedForKey("error_while_reading_file") + " (" + e.getMessage() + ")", e); } catch (InvalidXMLDataException e) { e.printStackTrace(); throw new ImportException( FlexoLocalization.localizedForKey("invalid_xml_data") + " (" + e.getMessage() + ")", e); } catch (InvalidObjectSpecificationException e) { e.printStackTrace(); throw new ImportException( FlexoLocalization.localizedForKey("invalid_object_specification") + " (" + e.getMessage() + ")", e); } catch (InvalidModelException e) { e.printStackTrace(); throw new ImportException( FlexoLocalization.localizedForKey("invalid_model") + " (" + e.getMessage() + ")", e); } catch (AccessorInvocationException e) { e.printStackTrace(); throw new ImportException( FlexoLocalization.localizedForKey("model_error") + " (" + e.getMessage() + ")", e); } catch (SAXException e) { e.printStackTrace(); throw new ImportException(FlexoLocalization.localizedForKey("xml_error") + " (" + e.getMessage() + ")", e); } catch (ParserConfigurationException e) { e.printStackTrace(); throw new ImportException(FlexoLocalization.localizedForKey("parser_configuration_exception") + " (" + e.getMessage() + ")", e); } catch (JDOMException e) { e.printStackTrace(); throw new ImportException(FlexoLocalization.localizedForKey("xml_error") + " (" + e.getMessage() + ")", e); } }
From source file:com.github.sampov2.OneJarMojo.java
private void addToZip(JarOutputStream out, ZipEntry entry, InputStream in) throws IOException { try {/*from w w w .j a v a 2 s .co m*/ out.putNextEntry(entry); IOUtils.copy(in, out); out.closeEntry(); } catch (ZipException e) { if (e.getMessage().startsWith("duplicate entry")) { // A Jar with the same name was already added. Let's add this one using a modified name: final ZipEntry alternativeEntry = new ZipEntry(entry.getName() + "-DUPLICATE-FILENAME-" + alternativeEntryCounter.incrementAndGet() + ".jar"); addToZip(out, alternativeEntry, in); } else { throw e; } } }
From source file:org.geoserver.opensearch.rest.AbstractOpenSearchController.java
protected <T extends ZipPart> Map<T, byte[]> parsePartsFromZip(InputStream body, T[] parts) throws IOException { // check the zip contents and map to the expected parts Map<T, byte[]> result = new HashMap<>(); try {//from w w w . j a v a 2 s. co m ZipInputStream zis = new ZipInputStream(body); ZipEntry entry = null; while ((entry = zis.getNextEntry()) != null) { String name = entry.getName(); T part = null; for (T zp : parts) { if (zp.matches(name)) { part = zp; break; } } if (part != null) { result.put(part, IOUtils.toByteArray(zis)); } else { LOGGER.warning("Ignoring un-recognized entry in zip file:" + name); } } } catch (ZipException e) { throw new RestException(e.getMessage(), HttpStatus.BAD_REQUEST); } return result; }
From source file:se.bitcraze.crazyflielib.bootloader.Bootloader.java
/** * Basic check if a file is a Zip file//from w w w. java 2 s. com * * @param file * @return true if file is a Zip file, false otherwise */ //TODO: how can this be improved? private boolean isZipFile(File file) { if (file != null && file.exists() && file.getName().endsWith(".zip")) { ZipFile zf = null; try { zf = new ZipFile(file); return zf.size() > 0; } catch (ZipException e) { mLogger.error(e.getMessage()); } catch (IOException e) { mLogger.error(e.getMessage()); } finally { if (zf != null) { try { zf.close(); } catch (IOException e) { mLogger.error(e.getMessage()); } } } } return false; }