List of usage examples for java.util.zip ZipException ZipException
public ZipException(String s)
ZipException
with the specified detail message. From source file:org.opencms.importexport.CmsImportHelper.java
/** * Returns a byte array containing the content of the file.<p> * * @param filename the name of the file to read, relative to the folder or zip file * // ww w . j a v a 2 s.c om * @return a byte array containing the content of the file * * @throws CmsImportExportException if something goes wrong */ public byte[] getFileBytes(String filename) throws CmsImportExportException { try { // is this a zip-file? if (getZipFile() != null) { // yes ZipEntry entry = getZipFile().getEntry(filename); // path to file might be relative, too if ((entry == null) && filename.startsWith("/")) { entry = m_zipFile.getEntry(filename.substring(1)); } if (entry == null) { throw new ZipException(Messages.get().getBundle() .key(Messages.LOG_IMPORTEXPORT_FILE_NOT_FOUND_IN_ZIP_1, filename)); } InputStream stream = getZipFile().getInputStream(entry); int size = new Long(entry.getSize()).intValue(); return CmsFileUtil.readFully(stream, size); } else { // no - use directory File file = new File(getFolder(), filename); return CmsFileUtil.readFile(file); } } catch (FileNotFoundException fnfe) { CmsMessageContainer msg = Messages.get().container(Messages.ERR_IMPORTEXPORT_FILE_NOT_FOUND_1, filename); if (LOG.isErrorEnabled()) { LOG.error(msg.key(), fnfe); } throw new CmsImportExportException(msg, fnfe); } catch (IOException ioe) { CmsMessageContainer msg = Messages.get().container(Messages.ERR_IMPORTEXPORT_ERROR_READING_FILE_1, filename); if (LOG.isErrorEnabled()) { LOG.error(msg.key(), ioe); } throw new CmsImportExportException(msg, ioe); } }
From source file:org.opencms.importexport.CmsImportHelper.java
/** * Returns a stream for the content of the file.<p> * * @param fileName the name of the file to stream, relative to the folder or zip file * //from w ww . jav a 2 s . c o m * @return an input stream for the content of the file, remember to close it after using * * @throws CmsImportExportException if something goes wrong */ public InputStream getFileStream(String fileName) throws CmsImportExportException { try { InputStream stream = null; // is this a zip-file? if (getZipFile() != null) { // yes ZipEntry entry = getZipFile().getEntry(fileName); // path to file might be relative, too if ((entry == null) && fileName.startsWith("/")) { entry = getZipFile().getEntry(fileName.substring(1)); } if (entry == null) { throw new ZipException(Messages.get().getBundle() .key(Messages.LOG_IMPORTEXPORT_FILE_NOT_FOUND_IN_ZIP_1, fileName)); } stream = getZipFile().getInputStream(entry); } else { // no - use directory File file = new File(getFolder(), CmsImportExportManager.EXPORT_MANIFEST); stream = new FileInputStream(file); } return stream; } catch (Exception ioe) { CmsMessageContainer msg = Messages.get().container(Messages.ERR_IMPORTEXPORT_ERROR_READING_FILE_1, fileName); if (LOG.isErrorEnabled()) { LOG.error(msg.key(), ioe); } throw new CmsImportExportException(msg, ioe); } }
From source file:utils.ZipUtils.java
static public void unzipArchive(File archive, File outputDir) throws ZipException { try {/*from w w w . j a v a2 s . co m*/ ZipFile zipfile = new ZipFile(archive); for (Enumeration<? extends ZipEntry> e = zipfile.entries(); e.hasMoreElements();) { ZipEntry entry = e.nextElement(); unzipEntry(zipfile, entry, outputDir); } } catch (Exception e) { String msg = "Failed to extract archive: " + archive; logger.error(msg, e); throw new ZipException(msg); } }