Package java.util.zip

Examples of java.util.zip.ZipOutputStream


  /**
   * Zips the given file.
   */
  public static File zip(File file) throws IOException {
    String outFilename = file.getAbsolutePath() + ".zip";
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
        outFilename));
    FileInputStream in = new FileInputStream(file);
    out.putNextEntry(new ZipEntry(file.getName()));
    byte[] buf = new byte[4096];
    int len;
    while ((len = in.read(buf)) > 0) {
      out.write(buf, 0, len);
    }
    out.closeEntry();
    in.close();
    out.close();
    return new File(outFilename);
  }
View Full Code Here


                              final String file, final String encoding, Set<String> keySet) throws Exception {
        exportOpenDocumentSpreadsheet(new File(file), database, keySet);
    }

    public static void storeOpenDocumentSpreadsheetFile(File file, InputStream source) throws Exception {
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file)));

        try {
           
            //addResourceFile("mimetype", "/resource/ods/mimetype", out);
            ZipEntry ze = new ZipEntry("mimetype");
            String mime = "application/vnd.oasis.opendocument.spreadsheet";
            ze.setMethod(ZipEntry.STORED);
            ze.setSize(mime.length());
            CRC32 crc = new CRC32();
            crc.update(mime.getBytes());
            ze.setCrc(crc.getValue());
            out.putNextEntry(ze);
            for (int i=0; i<mime.length(); i++) {
                out.write(mime.charAt(i));
            }
            out.closeEntry();

            ZipEntry zipEntry = new ZipEntry("content.xml");
            //zipEntry.setMethod(ZipEntry.DEFLATED);
            out.putNextEntry(zipEntry);
            int c = -1;
            while ((c = source.read()) >= 0) {
                out.write(c);
            }
            out.closeEntry();

            // Add manifest (required for OOo 2.0) and "meta.xml": These are in the
            // resource/ods directory, and are copied verbatim into the zip file.
            addResourceFile("meta.xml", "/resource/ods/meta.xml", out);

            addResourceFile("META-INF/manifest.xml", "/resource/ods/manifest.xml", out);

            //zipEntry = new ZipEntry()

        } finally {
            out.close();
        }
    }
View Full Code Here

                              final String file, final String encoding, Set<String> keySet) throws Exception {
        exportOpenOfficeCalc(new File(file), database, keySet);
    }

    public static void storeOpenOfficeFile(File file, InputStream source) throws Exception {
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
        try {
            ZipEntry zipEntry = new ZipEntry("content.xml");
            out.putNextEntry(zipEntry);
            int c = -1;
            while ((c = source.read()) >= 0) {
                out.write(c);
            }
            out.closeEntry();

            // Add manifest (required for OOo 2.0), "meta.xml", "mimetype" files. These are in the
            // resource/openoffice directory, and are copied verbatim into the zip file.
            addResourceFile("meta.xml", "/resource/openoffice/meta.xml", out);
            addResourceFile("mimetype", "/resource/openoffice/mimetype", out);
            addResourceFile("META-INF/manifest.xml", "/resource/openoffice/manifest.xml", out);

            //zipEntry = new ZipEntry()

        } finally {
            out.close();
        }
    }
View Full Code Here

    FileOutputStream fos = null;

    try
    {
      fos = new FileOutputStream(file);
      ZipOutputStream zipos = new ZipOutputStream(fos);
      zipos.setMethod(ZipOutputStream.DEFLATED);
     
      ZipEntry propsEntry = new ZipEntry("jasperreports_extension.properties");
      zipos.putNextEntry(propsEntry);
      Properties props = new Properties();
      props.put(PROPERTY_XML_CHART_THEME_REGISTRY_FACTORY, XmlChartThemeExtensionsRegistryFactory.class.getName());
      props.put(XML_CHART_THEME_PROPERTY_PREFIX + themeName, themeName + ".jrctx");
      props.store(zipos, null);

      ZipEntry jrctxEntry = new ZipEntry(themeName + ".jrctx");
      zipos.putNextEntry(jrctxEntry);
      XmlChartTheme.saveSettings(settings, new OutputStreamWriter(zipos));

      zipos.flush();
      zipos.finish();
    }
    finally
    {
      if (fos != null)
      {
View Full Code Here

  private void openStream(ZipOutStreamTaskAdapter zip, String filename) {
    byte[] savedZip = getBusiness().getSystemService().getCache()
        .getBlob(filename);
    ByteArrayOutputStream outData = new ByteArrayOutputStream();
    ZipOutputStream out = new ZipOutputStream(outData);
    zip.setOutStream(out);
    zip.setOutData(outData);
    if (savedZip != null) {
      ByteArrayInputStream inputData = new ByteArrayInputStream(savedZip);
      try {
        ZipInputStream in = new ZipInputStream(inputData);
        ZipEntry entry;
        while ((entry = in.getNextEntry()) != null) {
          out.putNextEntry(entry);
          if (!entry.isDirectory()) {
                    StreamUtils.readTo(in, out, false, false);
                }
                out.closeEntry();
        }
        in.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
View Full Code Here

            ((GZIPResponseWrapper) response).setCompress(false);
        }
           
        OutputStream out = null;
        try {
            ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
            for (int i = 0; i < uris.length; i++) {
                VFSResource res = DAVServlet.getDAVResource(launchSession, request, response, rootPath + "/" + uris[i]);
                zipit(zos, res, "");
            }
            zos.close();
        } catch (IOException ioe) {
            throw ioe;
        } finally {
            downloadCount++;
            Util.closeStream(out);
View Full Code Here

    }

    public int process() throws TransformerException, IOException, SAXException
    {
        ZipInputStream zis = new ZipInputStream(input);
        final ZipOutputStream zos = new ZipOutputStream(output);
        final OutputStreamWriter osw = new OutputStreamWriter(zos);

        Thread.currentThread()
                .setContextClassLoader(getClass().getClassLoader());

        TransformerFactory tf = TransformerFactory.newInstance();
        if (!tf.getFeature(SAXSource.FEATURE)
                || !tf.getFeature(SAXResult.FEATURE))
        {
            return 0;
        }

        SAXTransformerFactory saxtf = (SAXTransformerFactory) tf;
        Templates templates = null;
        if (xslt != null) {
            templates = saxtf.newTemplates(xslt);
        }

        // configuring outHandlerFactory
        // ///////////////////////////////////////////////////////

        EntryElement entryElement = getEntryElement(zos);

        ContentHandler outDocHandler = null;
        switch (outRepresentation) {
            case BYTECODE:
                outDocHandler = new OutputSlicingHandler(new ASMContentHandlerFactory(zos),
                        entryElement,
                        false);
                break;

            case MULTI_XML:
                outDocHandler = new OutputSlicingHandler(new SAXWriterFactory(osw,
                        true),
                        entryElement,
                        true);
                break;

            case SINGLE_XML:
                ZipEntry outputEntry = new ZipEntry(SINGLE_XML_NAME);
                zos.putNextEntry(outputEntry);
                outDocHandler = new SAXWriter(osw, false);
                break;

        }

        // configuring inputDocHandlerFactory
        // /////////////////////////////////////////////////
        ContentHandler inDocHandler;
        if (templates == null) {
            inDocHandler = outDocHandler;
        } else {
            inDocHandler = new InputSlicingHandler("class",
                    outDocHandler,
                    new TransformerHandlerFactory(saxtf,
                            templates,
                            outDocHandler));
        }
        ContentHandlerFactory inDocHandlerFactory = new SubdocumentHandlerFactory(inDocHandler);

        if (inDocHandler != null && inRepresentation != SINGLE_XML) {
            inDocHandler.startDocument();
            inDocHandler.startElement("",
                    "classes",
                    "classes",
                    new AttributesImpl());
        }

        int i = 0;
        ZipEntry ze;
        while ((ze = zis.getNextEntry()) != null) {
            update(ze.getName(), n++);
            if (isClassEntry(ze)) {
                processEntry(zis, ze, inDocHandlerFactory);
            } else {
                OutputStream os = entryElement.openEntry(getName(ze));
                copyEntry(zis, os);
                entryElement.closeEntry();
            }

            i++;
        }

        if (inDocHandler != null && inRepresentation != SINGLE_XML) {
            inDocHandler.endElement("", "classes", "classes");
            inDocHandler.endDocument();
        }

        if (outRepresentation == SINGLE_XML) {
            zos.closeEntry();
        }
        zos.flush();
        zos.close();

        return i;
    }
View Full Code Here

                optimize(files[i]);
            }
        } else if (f.getName().endsWith(".jar")) {
            File g = new File(f.getParentFile(), f.getName() + ".new");
            ZipFile zf = new ZipFile(f);
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(g));
            Enumeration<? extends ZipEntry> e = zf.entries();
            byte[] buf = new byte[10000];
            while (e.hasMoreElements()) {
                ZipEntry ze = e.nextElement();
                if (ze.isDirectory()) {
                    continue;
                }
                out.putNextEntry(ze);
                if (ze.getName().endsWith(".class")) {
                    ClassReader cr = new ClassReader(zf.getInputStream(ze));
                    // cr.accept(new ClassDump(), 0);
                    cr.accept(new ClassVerifier(), 0);
                }
                InputStream is = zf.getInputStream(ze);
                int n;
                do {
                    n = is.read(buf, 0, buf.length);
                    if (n != -1) {
                        out.write(buf, 0, n);
                    }
                } while (n != -1);
                out.closeEntry();
            }
            out.close();
            zf.close();
            if (!f.delete()) {
                throw new IOException("Cannot delete file " + f);
            }
            if (!g.renameTo(f)) {
View Full Code Here

        if ((format == null) || (format.equals("plain"))) {
            os = new BufferedOutputStream(new FileOutputStream(tf));
        } else if (format.equals("gzip")) {
            os = new GZIPOutputStream(new FileOutputStream(tf));
        } else if (format.equals("zip")) {
            final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file));
            String name = file.getName();
            if (name.endsWith(".zip")) name = name.substring(0, name.length() - 4);
            zos.putNextEntry(new ZipEntry(name + ".txt"));
            os = zos;
        }
        if(os != null) {
            for (final Iterator<byte[]> i = set.iterator(); i.hasNext(); ) {
                os.write(i.next());
View Full Code Here

        if ((format == null) || (format.equals("plain"))) {
            os = new BufferedOutputStream(new FileOutputStream(tf));
        } else if (format.equals("gzip")) {
            os = new GZIPOutputStream(new FileOutputStream(tf));
        } else if (format.equals("zip")) {
            final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file));
            String name = file.getName();
            if (name.endsWith(".zip")) name = name.substring(0, name.length() - 4);
            zos.putNextEntry(new ZipEntry(name + ".txt"));
            os = zos;
        }
        if (os != null) {
            final Iterator<Row.Entry> i = set.iterator();
            String key;
View Full Code Here

TOP

Related Classes of java.util.zip.ZipOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.