Examples of ZipOutputStream


Examples of java.util.zip.ZipOutputStream

    {
        // - retrieve the name of the file given by the path.
        final String name = path.replaceAll(
                PATH_REMOVE_PATTERN,
                "");
        final ZipOutputStream zipOutputStream = new ZipOutputStream(new java.io.FileOutputStream(modelArchive));
        final ZipEntry zipEntry = new ZipEntry(name);
        zipEntry.setMethod(ZipEntry.DEFLATED);
        zipOutputStream.putNextEntry(zipEntry);
        final java.io.FileInputStream inputStream = new java.io.FileInputStream(path);
        final byte[] buffer = new byte[1024];
        int n = 0;
        while ((n =
                inputStream.read(
                    buffer,
                    0,
                    buffer.length)) > 0)
        {
            zipOutputStream.write(
                buffer,
                0,
                n);
        }
        inputStream.close();
        zipOutputStream.closeEntry();
        zipOutputStream.close();
    }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

  /**
   * Save all MEMORY tables to encrypted storage.
   */
  public void save () {
    Connection connection = null;
    ZipOutputStream zip = null;
    try {
      connection = dataSource.getConnection();
     
      IVirtualFile storage = BackupUtil.rotate(this.storageDirectory, "backup", "dat", 20);
      storage.setIOHandler( new EncryptionIOHandler(provider) );
     
      zip = new ZipOutputStream(storage.getOutputStream());
     
      PrintWriter writer = new PrintWriter(zip, true);
      for (EncryptedTable table : getEncryptedTables(connection)) {
        ZipEntry entry = new ZipEntry(table.tableName + ".dat");
        zip.putNextEntry(entry);
        table.save(connection, writer);
        writer.flush();
        zip.closeEntry();
      }
      zip.flush();
      zip.close();
    } catch (Exception e) {
      if (zip != null) {
        try {
          zip.close();
          BackupUtil.reverseRotation(this.storageDirectory, "backup", "dat", 20);
        }
        catch (Exception ee) {
          throw ThrowableManagerRegistry.caught(ee);
        }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

   * @see net.sourceforge.squirrel_sql.client.update.UpdateUtil#createZipFile(FileWrapper, FileWrapper[])
   */
  public void createZipFile(FileWrapper zipFile, FileWrapper... sourceFiles) throws FileNotFoundException,
    IOException
  {
    ZipOutputStream os = new ZipOutputStream(new FileOutputStream(zipFile.getAbsolutePath()));
    zipFileOs(os, sourceFiles);
    os.close();
  }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

  /**
   *
   */
  public void zipEntries(OutputStream os) throws IOException
  {
    ZipOutputStream zipos = new ZipOutputStream(os);
    zipos.setMethod(ZipOutputStream.DEFLATED);
   
    for (int i = 0; i < exportZipEntries.size(); i++)
    {
      ExportZipEntry exportZipEntry = (ExportZipEntry)exportZipEntries.get(i);
      ZipEntry zipEntry = new ZipEntry(exportZipEntry.getName());
      zipos.putNextEntry(zipEntry);
      exportZipEntry.writeData(zipos);
    }
   
    zipos.flush();
    zipos.finish();
  }
View Full Code Here

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

Examples of java.util.zip.ZipOutputStream

                              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

Examples of java.util.zip.ZipOutputStream

                              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

Examples of java.util.zip.ZipOutputStream

    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

Examples of java.util.zip.ZipOutputStream

  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

Examples of java.util.zip.ZipOutputStream

            ((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
TOP
Copyright © 2018 www.massapi.com. 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.