List of usage examples for java.util.zip ZipException getMessage
public String getMessage()
From source file:com.ikon.util.DocConverter.java
/** * Convert ZIP to PDF//from ww w . j ava2 s . c o m */ @SuppressWarnings("rawtypes") public void zip2pdf(File input, File output) throws ConversionException, DatabaseException, IOException { log.debug("** Convert from ZIP to PDF **"); FileOutputStream fos = null; ZipFile zipFile = null; try { fos = new FileOutputStream(output); // Make conversion zipFile = new ZipFile(input); Document doc = new Document(PageSize.A4); PdfWriter.getInstance(doc, fos); doc.open(); for (Enumeration e = zipFile.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); doc.add(new Paragraph(12F, entry.getName())); } doc.close(); zipFile.close(); } catch (ZipException e) { throw new ConversionException("Exception in conversion: " + e.getMessage(), e); } catch (DocumentException e) { throw new ConversionException("Exception in conversion: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(fos); } }
From source file:eu.esdihumboldt.hale.io.appschema.writer.AppSchemaFileWriterTest.java
private void checkArchive(File archive) throws IOException { final File tempFile = File.createTempFile(Long.toString(System.currentTimeMillis()), ".xml"); ZipInputStream zis = null;/*from w ww . ja v a 2 s . c o m*/ Document doc = null; try { zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(archive))); ZipEntry lcvWsDir = zis.getNextEntry(); checkDirEntry(lcvWsDir, "lcv/"); zis.closeEntry(); ZipEntry lcvWsFile = zis.getNextEntry(); checkFileEntry(lcvWsFile, "lcv/" + AppSchemaIO.WORKSPACE_FILE); doc = readDocument(zis); checkWorkspaceDocument(doc, "lcv_workspace", "lcv"); zis.closeEntry(); ZipEntry lcvNsFile = zis.getNextEntry(); checkFileEntry(lcvNsFile, "lcv/" + AppSchemaIO.NAMESPACE_FILE); doc = readDocument(zis); checkNamespaceDocument(doc, "lcv_namespace", "lcv", "http://inspire.ec.europa.eu/schemas/lcv/3.0"); zis.closeEntry(); ZipEntry lcvDataStoreDir = zis.getNextEntry(); checkDirEntry(lcvDataStoreDir, "lcv/LandCoverVector/"); zis.closeEntry(); ZipEntry lcvDataStoreFile = zis.getNextEntry(); checkFileEntry(lcvDataStoreFile, "lcv/LandCoverVector/" + AppSchemaIO.DATASTORE_FILE); doc = readDocument(zis); assertNotNull(doc); assertEquals("LandCoverVector_datastore", getFirstElementByTagName(doc.getDocumentElement(), "id").getTextContent()); assertEquals("LandCoverVector", getFirstElementByTagName(doc.getDocumentElement(), "name").getTextContent()); Element wsEl = getFirstElementByTagName(doc.getDocumentElement(), "workspace"); assertNotNull(wsEl); assertEquals("lcv_workspace", getFirstElementByTagName(wsEl, "id").getTextContent()); NodeList paramEntries = doc.getDocumentElement().getElementsByTagName("entry"); assertNotNull(paramEntries); assertEquals(3, paramEntries.getLength()); for (int i = 0; i < paramEntries.getLength(); i++) { Node param = paramEntries.item(i); Node key = param.getAttributes().getNamedItem("key"); if ("dbtype".equals(key.getTextContent())) { assertEquals("app-schema", param.getTextContent()); } else if ("namespace".equals(key.getTextContent())) { assertEquals("http://inspire.ec.europa.eu/schemas/lcv/3.0", param.getTextContent()); } else if ("url".equals(key.getTextContent())) { assertEquals("file:./workspaces/lcv/LandCoverVector/LandCoverVector.xml", param.getTextContent()); } else { fail("Unknown connection parameter found: " + key.getTextContent()); } } zis.closeEntry(); ZipEntry mappingFile = zis.getNextEntry(); checkFileEntry(mappingFile, "lcv/LandCoverVector/LandCoverVector.xml"); ByteStreams.copy(zis, new FileOutputStream(tempFile)); assertTrue(isMappingValid(tempFile)); zis.closeEntry(); ZipEntry unitFtDir = zis.getNextEntry(); checkDirEntry(unitFtDir, "lcv/LandCoverVector/LandCoverUnit/"); zis.closeEntry(); ZipEntry unitFtFile = zis.getNextEntry(); checkFileEntry(unitFtFile, "lcv/LandCoverVector/LandCoverUnit/" + AppSchemaIO.FEATURETYPE_FILE); doc = readDocument(zis); checkFeatureTypeDocument(doc, "LandCoverUnit"); zis.closeEntry(); ZipEntry unitLayerFile = zis.getNextEntry(); checkFileEntry(unitLayerFile, "lcv/LandCoverVector/LandCoverUnit/" + AppSchemaIO.LAYER_FILE); doc = readDocument(zis); checkLayerDocument(doc, "LandCoverUnit"); zis.closeEntry(); ZipEntry datasetFtDir = zis.getNextEntry(); checkDirEntry(datasetFtDir, "lcv/LandCoverVector/LandCoverDataset/"); zis.closeEntry(); ZipEntry datasetFtFile = zis.getNextEntry(); checkFileEntry(datasetFtFile, "lcv/LandCoverVector/LandCoverDataset/" + AppSchemaIO.FEATURETYPE_FILE); doc = readDocument(zis); checkFeatureTypeDocument(doc, "LandCoverDataset"); zis.closeEntry(); ZipEntry datasetLayerFile = zis.getNextEntry(); checkFileEntry(datasetLayerFile, "lcv/LandCoverVector/LandCoverDataset/" + AppSchemaIO.LAYER_FILE); doc = readDocument(zis); checkLayerDocument(doc, "LandCoverDataset"); zis.closeEntry(); ZipEntry baseWsDir = zis.getNextEntry(); checkDirEntry(baseWsDir, "base/"); zis.closeEntry(); ZipEntry baseWsFile = zis.getNextEntry(); checkFileEntry(baseWsFile, "base/" + AppSchemaIO.WORKSPACE_FILE); doc = readDocument(zis); checkWorkspaceDocument(doc, "base_workspace", "base"); zis.closeEntry(); ZipEntry baseNsFile = zis.getNextEntry(); checkFileEntry(baseNsFile, "base/" + AppSchemaIO.NAMESPACE_FILE); doc = readDocument(zis); checkNamespaceDocument(doc, "base_namespace", "base", "http://inspire.ec.europa.eu/schemas/base/3.3"); zis.closeEntry(); ZipEntry gmlWsDir = zis.getNextEntry(); checkDirEntry(gmlWsDir, "gml/"); zis.closeEntry(); ZipEntry gmlWsFile = zis.getNextEntry(); checkFileEntry(gmlWsFile, "gml/" + AppSchemaIO.WORKSPACE_FILE); doc = readDocument(zis); checkWorkspaceDocument(doc, "gml_workspace", "gml"); zis.closeEntry(); ZipEntry gmlNsFile = zis.getNextEntry(); checkFileEntry(gmlNsFile, "gml/" + AppSchemaIO.NAMESPACE_FILE); doc = readDocument(zis); checkNamespaceDocument(doc, "gml_namespace", "gml", "http://www.opengis.net/gml/3.2"); zis.closeEntry(); ZipEntry xlinkWsDir = zis.getNextEntry(); checkDirEntry(xlinkWsDir, "xlink/"); zis.closeEntry(); ZipEntry xlinkWsFile = zis.getNextEntry(); checkFileEntry(xlinkWsFile, "xlink/" + AppSchemaIO.WORKSPACE_FILE); doc = readDocument(zis); checkWorkspaceDocument(doc, "xlink_workspace", "xlink"); zis.closeEntry(); ZipEntry xlinkNsFile = zis.getNextEntry(); checkFileEntry(xlinkNsFile, "xlink/" + AppSchemaIO.NAMESPACE_FILE); doc = readDocument(zis); checkNamespaceDocument(doc, "xlink_namespace", "xlink", "http://www.w3.org/1999/xlink"); zis.closeEntry(); ZipEntry xsiWsDir = zis.getNextEntry(); checkDirEntry(xsiWsDir, "xsi/"); zis.closeEntry(); ZipEntry xsiWsFile = zis.getNextEntry(); checkFileEntry(xsiWsFile, "xsi/" + AppSchemaIO.WORKSPACE_FILE); doc = readDocument(zis); checkWorkspaceDocument(doc, "xsi_workspace", "xsi"); zis.closeEntry(); ZipEntry xsiNsFile = zis.getNextEntry(); checkFileEntry(xsiNsFile, "xsi/" + AppSchemaIO.NAMESPACE_FILE); doc = readDocument(zis); checkNamespaceDocument(doc, "xsi_namespace", "xsi", AppSchemaMappingUtils.XSI_URI); zis.closeEntry(); assertNull(zis.getNextEntry()); } catch (ZipException e) { fail("Exception reading generated ZIP archive: " + e.getMessage()); } finally { if (tempFile != null) tempFile.delete(); if (zis != null) zis.close(); } }
From source file:org.eclipse.emf.mwe.utils.StandaloneSetup.java
protected void registerBundle(File file) { JarFile jarFile = null;//from w ww . j av a 2 s . c o m try { jarFile = new JarFile(file); log.debug("Trying to determine project name from Manifest for " + jarFile.getName()); String name = getBundleNameFromManifest(jarFile); if (name == null) { log.debug("Trying to determine project name from file name for " + jarFile.getName()); name = getBundleNameFromJarName(jarFile.getName()); } if (name != null) { final int indexOf = name.indexOf(';'); if (indexOf > 0) name = name.substring(0, indexOf); String path = "archive:" + file.getCanonicalFile().toURI() + "!/"; URI uri = URI.createURI(path); registerMapping(name, uri); } else { log.debug("Could not determine project name for " + jarFile.getName() + ". No project mapping will be added."); } } catch (ZipException e) { log.warn("Could not open Jar file " + file.getAbsolutePath() + "."); } catch (Exception e) { handleException(file, e); } finally { try { if (jarFile != null) jarFile.close(); } catch (IOException e) { log.error(e.getMessage(), e); } } }
From source file:org.guvnor.m2repo.backend.server.GuvnorM2Repository.java
private String loadGAVFromJarInternal(final File file) { InputStream is = null;/*from w w w . j a va 2 s . co m*/ InputStreamReader isr = null; try { ZipFile zip = new ZipFile(file); for (Enumeration e = zip.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); if (entry.getName().startsWith("META-INF/maven") && entry.getName().endsWith("pom.properties")) { is = zip.getInputStream(entry); isr = new InputStreamReader(is, "UTF-8"); StringBuilder sb = new StringBuilder(); for (int c = isr.read(); c != -1; c = isr.read()) { sb.append((char) c); } return sb.toString(); } } } catch (ZipException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } finally { if (isr != null) { try { isr.close(); } catch (IOException e) { } } if (is != null) { try { is.close(); } catch (IOException e) { } } } return null; }
From source file:com.ephesoft.dcma.webservice.service.EphesoftWebService.java
private void renameZipFileEntries(final File oldZipFile, final BatchClass batchClass, final String oldBatchInstanceIdentifier, final String newBatchInstanceIdentfier) { LOGGER.info("Zip files to be modified " + oldZipFile.getAbsolutePath()); String finalZipPath = oldZipFile.getAbsolutePath(); File finalZipFile = new File(finalZipPath); String destDirectory = finalZipFile.getParent(); String unzippedFilePath = finalZipFile.getAbsolutePath(); LOGGER.info("Unziping the " + unzippedFilePath + CONSTANT_TO + destDirectory); FileUtils.unzip(finalZipFile, destDirectory); ZipFile zipFile = null;//from w w w. j ava2 s. c om try { zipFile = new ZipFile(finalZipFile); // Only 1st entry picked. Considering that our zip file contains only a single file. String xmlFileName = zipFile.entries().nextElement().getName(); StringBuilder xmlFileNameBuilder = new StringBuilder(); xmlFileNameBuilder.append(destDirectory); xmlFileNameBuilder.append(File.separator); xmlFileNameBuilder.append(xmlFileName); String xmlFilePath = xmlFileNameBuilder.toString(); File xmlFile = new File(xmlFilePath); xmlFileName = xmlFileName.replaceAll(oldBatchInstanceIdentifier, newBatchInstanceIdentfier); StringBuilder newXmlFileNameBuilder = new StringBuilder(); newXmlFileNameBuilder.append(destDirectory); newXmlFileNameBuilder.append(File.separator); newXmlFileNameBuilder.append(xmlFileName); String newXmlFilePath = newXmlFileNameBuilder.toString(); File newXmlFile = new File(newXmlFilePath); LOGGER.info("Renaming " + unzippedFilePath + CONSTANT_TO + xmlFileName); xmlFile.renameTo(newXmlFile); List<String> fileNames = new ArrayList<String>(); fileNames.add(newXmlFile.getAbsolutePath()); LOGGER.info("Zipping the altered files to " + finalZipPath); FileUtils.zipMultipleFiles(fileNames, finalZipPath); updateTranferredBatch(newBatchInstanceIdentfier, batchClass, oldBatchInstanceIdentifier); newXmlFile.delete(); } catch (ZipException e) { LOGGER.error("Error Creating zip file " + e.getMessage(), e); } catch (IOException e) { LOGGER.error("I/O Error while Creating zip file " + e.getMessage(), e); } }
From source file:com.ephesoft.dcma.webservice.service.EphesoftWebService.java
private void renameHocrFiles(final File oldXmlFile, final String newBatchInstanceIdentfier, final String oldBatchInstanceIdentifier) { LOGGER.info("Retrived list of zip files from " + oldXmlFile.getAbsolutePath()); String finalZipPath = oldXmlFile.getAbsolutePath(); File finalZipFile = new File(finalZipPath); String destDirectory = finalZipFile.getParent(); String unzippedFilePath = finalZipFile.getAbsolutePath(); LOGGER.info("Unziping the " + unzippedFilePath + CONSTANT_TO + destDirectory); FileUtils.unzip(finalZipFile, destDirectory); ZipFile zipFile = null;// ww w . ja v a2 s . c o m try { zipFile = new ZipFile(finalZipFile); // Only 1st entry picked. Considering that our zip file contains only a single file. String xmlFileName = zipFile.entries().nextElement().getName(); StringBuilder xmlFileNameBuilder = new StringBuilder(); xmlFileNameBuilder.append(destDirectory); xmlFileNameBuilder.append(File.separator); xmlFileNameBuilder.append(xmlFileName); String xmlFilePath = xmlFileNameBuilder.toString(); File xmlFile = new File(xmlFilePath); xmlFileName = xmlFileName.replaceAll(oldBatchInstanceIdentifier, newBatchInstanceIdentfier); StringBuilder newXmlFileNameBuilder = new StringBuilder(); newXmlFileNameBuilder.append(destDirectory); newXmlFileNameBuilder.append(File.separator); newXmlFileNameBuilder.append(xmlFileName); String newXmlFilePath = newXmlFileNameBuilder.toString(); File newXmlFile = new File(newXmlFilePath); LOGGER.info("Renaming " + unzippedFilePath + CONSTANT_TO + xmlFileName); xmlFile.renameTo(newXmlFile); List<String> fileNames = new ArrayList<String>(); fileNames.add(newXmlFile.getAbsolutePath()); LOGGER.info("Zipping the altered files to " + finalZipPath); FileUtils.zipMultipleFiles(fileNames, finalZipPath); newXmlFile.delete(); } catch (ZipException e) { LOGGER.error("Error Creating zip file " + e.getMessage(), e); } catch (IOException e) { LOGGER.error("I/O Error while Creating zip file " + e.getMessage(), e); } }
From source file:nl.nn.adapterframework.jdbc.JdbcTransactionalStorage.java
protected Object retrieveObject(ResultSet rs, int columnIndex) throws ClassNotFoundException, JdbcException, IOException, SQLException { try {//from w ww . java2 s . com if (isBlobsCompressed()) { try { return retrieveObject(rs, columnIndex, true); } catch (ZipException e1) { log.warn(getLogPrefix() + "could not extract compressed blob, trying non-compressed: (" + ClassUtils.nameOf(e1) + ") " + e1.getMessage()); return retrieveObject(rs, columnIndex, false); } } try { return retrieveObject(rs, columnIndex, false); } catch (Exception e1) { log.warn(getLogPrefix() + "could not extract non-compressed blob, trying compressed: (" + ClassUtils.nameOf(e1) + ") " + e1.getMessage()); return retrieveObject(rs, columnIndex, true); } } catch (Exception e2) { throw new JdbcException("could not extract message", e2); } }
From source file:org.springframework.cloud.netflix.zuul.filters.post.SendResponseFilter.java
private void writeResponse() throws Exception { RequestContext context = RequestContext.getCurrentContext(); // there is no body to send if (context.getResponseBody() == null && context.getResponseDataStream() == null) { return;/* w ww.j av a 2s. co m*/ } HttpServletResponse servletResponse = context.getResponse(); if (servletResponse.getCharacterEncoding() == null) { // only set if not set servletResponse.setCharacterEncoding("UTF-8"); } OutputStream outStream = servletResponse.getOutputStream(); InputStream is = null; try { if (RequestContext.getCurrentContext().getResponseBody() != null) { String body = RequestContext.getCurrentContext().getResponseBody(); writeResponse(new ByteArrayInputStream(body.getBytes(servletResponse.getCharacterEncoding())), outStream); return; } boolean isGzipRequested = false; final String requestEncoding = context.getRequest().getHeader(ZuulHeaders.ACCEPT_ENCODING); if (requestEncoding != null && HTTPRequestUtils.getInstance().isGzipped(requestEncoding)) { isGzipRequested = true; } is = context.getResponseDataStream(); InputStream inputStream = is; if (is != null) { if (context.sendZuulResponse()) { // if origin response is gzipped, and client has not requested gzip, // decompress stream // before sending to client // else, stream gzip directly to client if (context.getResponseGZipped() && !isGzipRequested) { // If origin tell it's GZipped but the content is ZERO bytes, // don't try to uncompress final Long len = context.getOriginContentLength(); if (len == null || len > 0) { try { inputStream = new GZIPInputStream(is); } catch (java.util.zip.ZipException ex) { log.debug("gzip expected but not " + "received assuming unencoded response " + RequestContext.getCurrentContext().getRequest().getRequestURL() .toString()); inputStream = is; } } else { // Already done : inputStream = is; } } else if (context.getResponseGZipped() && isGzipRequested) { servletResponse.setHeader(ZuulHeaders.CONTENT_ENCODING, "gzip"); } writeResponse(inputStream, outStream); } } } finally { /** * Closing the wrapping InputStream itself has no effect on closing the underlying tcp connection since it's a wrapped stream. I guess for http * keep-alive. When closing the wrapping stream it tries to reach the end of the current request, which is impossible for infinite http streams. So * instead of closing the InputStream we close the HTTP response. * * @author Johannes Edmeier */ try { Object zuulResponse = RequestContext.getCurrentContext().get("zuulResponse"); if (zuulResponse instanceof Closeable) { ((Closeable) zuulResponse).close(); } outStream.flush(); // The container will close the stream for us } catch (IOException ex) { log.warn("Error while sending response to client: " + ex.getMessage()); } } }