Examples of ZipOutputStream


Examples of java.util.zip.ZipOutputStream

        try {
            if (new File(destFile).isDirectory()) {
                throw new IOException("Can't create the file as a directory with this name already exists: " + destFile);
            }
            OutputStream out = new BufferedOutputStream(new FileOutputStream(destFile));
            ZipOutputStream zipOut;
            if (jar) {
                zipOut = new JarOutputStream(out);
            } else {
                zipOut = new ZipOutputStream(out);
            }
            if (storeOnly) {
                zipOut.setMethod(ZipOutputStream.STORED);
            }
            zipOut.setLevel(Deflater.BEST_COMPRESSION);
            for (File file : files) {
                String fileName = file.getPath();
                String entryName = removeBase(basePath, fileName);
                byte[] data = readFile(file);
                ZipEntry entry = new ZipEntry(entryName);
                CRC32 crc = new CRC32();
                crc.update(data);
                entry.setSize(file.length());
                entry.setCrc(crc.getValue());
                zipOut.putNextEntry(entry);
                zipOut.write(data);
                zipOut.closeEntry();
            }
            zipOut.closeEntry();
            zipOut.close();
            return new File(destFile).length() / 1024;
        } catch (IOException e) {
            throw new RuntimeException("Error creating file " + destFile, e);
        }
    }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

            IOUtils.delete(zipFileName);
        }
        OutputStream fileOut = null;
        try {
            fileOut = IOUtils.openFileOutputStream(zipFileName, false);
            ZipOutputStream zipOut = new ZipOutputStream(fileOut);
            for (String fileName : source) {
                String f = IOUtils.getCanonicalPath(fileName);
                if (!f.startsWith(base)) {
                    DbException.throwInternalError(f + " does not start with " + base);
                }
                if (f.endsWith(zipFileName)) {
                    continue;
                }
                if (IOUtils.isDirectory(fileName)) {
                    continue;
                }
                f = f.substring(base.length());
                f = BackupCommand.correctFileName(f);
                ZipEntry entry = new ZipEntry(f);
                zipOut.putNextEntry(entry);
                InputStream in = null;
                try {
                    in = IOUtils.openFileInputStream(fileName);
                    IOUtils.copyAndCloseInput(in, zipOut);
                } catch (FileNotFoundException e) {
                    // the file could have been deleted in the meantime
                    // ignore this (in this case an empty file is created)
                } finally {
                    IOUtils.closeSilently(in);
                }
                zipOut.closeEntry();
            }
            zipOut.closeEntry();
            zipOut.close();
        } catch (IOException e) {
            throw DbException.convertIOException(e, zipFileName);
        } finally {
            IOUtils.closeSilently(fileOut);
        }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

    File file = new File(zipName);
    if (file.exists()) {
      ZipFile zipFile = new ZipFile(file.getAbsolutePath());
      Enumeration zipEntries = zipFile.entries();
      // create your output zip file
      ZipOutputStream newZip = new ZipOutputStream(
        new FileOutputStream(new File(file.getAbsolutePath() + "_TMP")));

      // Get all data (except the oldFileName) from zip file and
      // write it to the tmp zip file
      while (zipEntries.hasMoreElements()) {
        entry = (ZipEntry) zipEntries.nextElement();
        if (entry.getName().equalsIgnoreCase(oldFileName))
          continue;
        newZip.putNextEntry(new ZipEntry(entry.getName()));
        InputStream is = zipFile.getInputStream(entry);
        try {
          dump(is,newZip);
        } finally {
          newZip.closeEntry();
          is.close();
        }
      }
      zipFile.close();

      // Write the new fileName to the zip
      entry = new ZipEntry(path);
      newZip.putNextEntry(entry);
      try {
        FileInputStream fis = new FileInputStream(newFileName);
        dump(fis,newZip);
        fis.close();
      } catch (Exception exc) {
        System.out.println("Error reading input file: " + newFileName + " " + exc);
        newZip.close();
        new File(file.getAbsolutePath() + "_TMP").delete();
        throw exc;
      } finally {
        newZip.flush();
        newZip.closeEntry();
        newZip.finish();
        newZip.close();
      }
      String toRename = file.getAbsolutePath() + "_TMP";
      new File(file.getAbsolutePath()).delete();
      new File(toRename).renameTo(file);
    }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

            out.close();
        } else {
            OutputStream out = null;
            try {
                out = new FileOutputStream(zipFile);
                ZipOutputStream zipOut = new ZipOutputStream(out);
                String baseName = base.getAbsolutePath();
                for (File f : list) {
                    String fileName = f.getAbsolutePath();
                    String entryName = fileName;
                    if (fileName.startsWith(baseName)) {
                        entryName = entryName.substring(baseName.length());
                    }
                    if (entryName.startsWith("\\")) {
                        entryName = entryName.substring(1);
                    }
                    if (!entryName.startsWith("/")) {
                        entryName = "/" + entryName;
                    }
                    ZipEntry entry = new ZipEntry(basePath + entryName);
                    zipOut.putNextEntry(entry);
                    InputStream in = null;
                    try {
                        in = new FileInputStream(fileName);
                        IOUtils.copyAndCloseInput(in, zipOut);
                    } finally {
                        IOUtils.closeSilently(in);
                    }
                    zipOut.closeEntry();
                }
                zipOut.closeEntry();
                zipOut.close();
            } finally {
                IOUtils.closeSilently(out);
            }
        }
        return zipFile;
View Full Code Here

Examples of java.util.zip.ZipOutputStream

     */
    public static void zipFile(String sSrcFileName, long lStart, String sDstFileName) throws FileNotFoundException, IOException {
        int nBufferSize = 4096;

        FileOutputStream dest = null;
        ZipOutputStream out = null;

        BufferedInputStream bis = null;
        File fDstFile = null;

        if (hasZipFile(sDstFileName)) {
            unzipFile(sDstFileName, 0, sDstFileName);
        }

        IOException ioe = null;

        try {
            dest = new FileOutputStream(sDstFileName + ZIP);
            out = new ZipOutputStream(new BufferedOutputStream(dest));
            ZipEntry entry = new ZipEntry(sDstFileName);
            out.putNextEntry(entry);

            bis = new BufferedInputStream(new FileInputStream(sSrcFileName), nBufferSize);
            bis.skip(lStart);

            byte[] data = new byte[nBufferSize];

            //It has combined the dest file if it exists or filled char after
            //executed the following codes.
            fDstFile = new File(sDstFileName);

            if (lStart > 0) {
                if (fDstFile.exists()) {
                    FileInputStream normalFile = new FileInputStream(fDstFile);
                    writeFully(normalFile, lStart, out, nBufferSize, data);
                    normalFile.close();
                }//end if
                else {
                    writeFully(lStart, out, nBufferSize, data);
                }//end else
            }
            //read from sSrcFileName into the sDstFileName
            while (true) {
                int nByte = bis.read(data);
                if (nByte == -1) {
                    break;
                }

                out.write(data, 0, nByte);
            }//end while
        } catch (IOException ioe1) {
            ioe = ioe1;
        } finally {
            try {
                if (bis != null) {
                    bis.close();
                }

                if (out != null) {
                    out.close();
                }

                if (dest != null) {
                    dest.close();
                }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

    documentOffsetsObs = new OutputBitStream( basenameSuffix + SimpleCompressedDocumentCollection.DOCUMENT_OFFSETS_EXTENSION );
    termOffsetsObs = new OutputBitStream( basenameSuffix + SimpleCompressedDocumentCollection.TERM_OFFSETS_EXTENSION );
    nonTermOffsetsObs = exact? new OutputBitStream( basenameSuffix + SimpleCompressedDocumentCollection.NONTERM_OFFSETS_EXTENSION ) : null;
    fieldContent = new IntArrayList();

    if ( hasNonText ) nonTextZipDataOutputStream = new DataOutputStream( nonTextZipOutputStream = new ZipOutputStream( new FastBufferedOutputStream( new FileOutputStream( basenameSuffix + ZipDocumentCollection.ZIP_EXTENSION ) ) ) );

    terms.clear();
    terms.trim( Scan.INITIAL_TERM_MAP_SIZE );
    if ( exact ) {
      nonTerms.clear();
View Full Code Here

Examples of java.util.zip.ZipOutputStream

    this.exact = exact;
  }

  public void open( CharSequence suffix ) throws FileNotFoundException {
    basenameSuffix = basename + suffix;
    zipDataOutputStream = new DataOutputStream( zipOut = new ZipOutputStream( new FileOutputStream( basenameSuffix + ZipDocumentCollection.ZIP_EXTENSION ) ) );
    numberOfDocuments = 0;
  }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

            IOUtils.delete(zipFileName);
        }
        OutputStream fileOut = null;
        try {
            fileOut = IOUtils.openFileOutputStream(zipFileName, false);
            ZipOutputStream zipOut = new ZipOutputStream(fileOut);
            String base = "";
            for (String fileName : list) {
                if (fileName.endsWith(Constants.SUFFIX_PAGE_FILE) || allFiles) {
                    base = IOUtils.getParent(fileName);
                    break;
                }
            }
            for (String fileName : list) {
                String f = IOUtils.getCanonicalPath(fileName);
                if (!f.startsWith(base)) {
                    DbException.throwInternalError(f + " does not start with " + base);
                }
                if (f.endsWith(zipFileName)) {
                    continue;
                }
                if (IOUtils.isDirectory(fileName)) {
                    continue;
                }
                f = f.substring(base.length());
                f = BackupCommand.correctFileName(f);
                ZipEntry entry = new ZipEntry(f);
                zipOut.putNextEntry(entry);
                InputStream in = null;
                try {
                    in = IOUtils.openFileInputStream(fileName);
                    IOUtils.copyAndCloseInput(in, zipOut);
                } catch (FileNotFoundException e) {
                    // the file could have been deleted in the meantime
                    // ignore this (in this case an empty file is created)
                } finally {
                    IOUtils.closeSilently(in);
                }
                zipOut.closeEntry();
                if (!quiet) {
                    out.println("Processed: " + fileName);
                }
            }
            zipOut.closeEntry();
            zipOut.close();
        } catch (IOException e) {
            throw DbException.convertIOException(e, zipFileName);
        } finally {
            IOUtils.closeSilently(fileOut);
        }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

            File zipFile = new File(zipFileName);
            if (!zipFile.getParentFile().exists()) {
                zipFile.getParentFile().mkdirs();
            }
            FileOutputStream fos = new FileOutputStream(zipFile);
            ZipOutputStream zoStream = new ZipOutputStream(fos);
            // zoStream.setMethod(ZipOutputStream.STORED);
            writeZipEntry(toBeZipped,
                    zoStream,
                    toBeZipped.getParent().length() + 1);
            zoStream.close();
        } catch (SecurityException se) {
            Debug.error("Security Exception caught while creating "
                    + zipFileName);
        }
    }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

    String tsv_filename = "irclog-"+bot.getName()+"-"+channel.getName()+"-"+channel.getServer().getServerName()+"-"+format.format(day.getTime())+".txt";

    setContentType("application/download");
    addHeader("Content-Disposition", "attachment; filename="+tsv_filename+".zip");
   
    ZipOutputStream zip_stream = new ZipOutputStream(getOutputStream());
    zip_stream.setLevel(9);
    zip_stream.setMethod(ZipOutputStream.DEFLATED);
    ZipEntry tsv_zip = new ZipEntry(tsv_filename);
    try
    {
      zip_stream.putNextEntry(tsv_zip);

      DownloadLogMessages log_messages = new DownloadLogMessages(zip_stream);
      try
      {
        DatabaseLogsFactory.get().getLogMessages(log_messages, bot, channel, day);
      }
      catch (LogManagerException e)
      {
        throw new EngineException(e);
      }
     
      zip_stream.closeEntry();
      zip_stream.close();
      // disabled since tomcat closes it anyhow and complains otherwise
      // binary_out.close();
    }
    catch (IOException e)
    {
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.