Package java.util.zip

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


    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

    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

            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

            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

    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

        this.archiveFile = archiveFile;
    }

    public void doArchive() throws Exception {
        FileOutputStream stream = new FileOutputStream(archiveFile);
        ZipOutputStream output = new ZipOutputStream(stream);
        compressFile(folderToArchive, output);
        output.close();
        stream.close();
    }
View Full Code Here

        }
        try {
            String name = db.getName();
            name = IOUtils.getFileName(name);
            OutputStream zip = IOUtils.openFileOutputStream(fileName, false);
            ZipOutputStream out = new ZipOutputStream(zip);
            db.flush();
            String fn = db.getName() + Constants.SUFFIX_PAGE_FILE;
            backupPageStore(out, fn, db.getPageStore());
            // synchronize on the database, to avoid concurrent temp file
            // creation / deletion / backup
            String base = IOUtils.getParent(fn);
            synchronized (db.getLobSyncObject()) {
                String prefix = db.getDatabasePath();
                String dir = IOUtils.getParent(prefix);
                dir = FileLister.getDir(dir);
                ArrayList<String> fileList = FileLister.getDatabaseFiles(dir, name, true);
                for (String n : fileList) {
                    if (n.endsWith(Constants.SUFFIX_LOB_FILE)) {
                        backupFile(out, base, n);
                    }
                }
            }
            out.close();
            zip.close();
        } catch (IOException e) {
            throw DbException.convertIOException(e, fileName);
        }
    }
View Full Code Here

  }
  public static final int BUFFER = 4096;
  public static void speedupZip(InputStream input, OutputStream output)
    throws IOException {
    ZipInputStream in = new ZipInputStream(input);
    ZipOutputStream out = new ZipOutputStream(output);
    ZipEntry inentry;
    ZipEntry outentry;
    int count;
    byte[] buffer = new byte[BUFFER];
    while ((inentry = in.getNextEntry()) != null) {
      outentry = new ZipEntry(inentry.getName());
      logger.debug("Extra: " + inentry.getExtra());
      outentry.setExtra(inentry.getExtra());
      logger.debug("time: " + inentry.getTime());
      outentry.setTime(inentry.getTime());
      logger.debug("method: " + inentry.getMethod());
      outentry.setMethod(inentry.getMethod());
      logger.debug("comment: " + inentry.getComment());
      outentry.setComment(inentry.getComment());
      logger.debug("CRC: " + inentry.getCrc());
      if (inentry.getCrc() != -1) {
        outentry.setCrc(inentry.getCrc());
      }
      logger.debug("size: " + inentry.getSize());
      if (inentry.getSize() != -1) {
        outentry.setSize(inentry.getSize());
      }
      out.putNextEntry(outentry);
      if (!inentry.isDirectory()) {
        if (inentry.getName().endsWith(".jar")
          || inentry.getName().endsWith(".zip")
          || inentry.getName().endsWith(".war")
          || inentry.getName().endsWith(".ear")) {
          speedupZip(in, out);
        } else if (inentry.getName().endsWith(".class")) {
          speedup(in, inentry.getName(), out);
        } else {
          while ((count = in.read(buffer, 0, BUFFER)) != -1) {
            out.write(buffer, 0, count);
          }
        }

      }
      out.closeEntry();
      in.closeEntry();
    }
    out.close();
    in.close();
  }
View Full Code Here

        outFile.delete();
      }

      AEDiagnostics.flushPendingLogs();

      ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFile));

      // %USERDIR%\logs
      File logPath = new File(SystemProperties.getUserPath(), "logs");
      File[] files = logPath.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
          return pathname.getName().endsWith(".log");
        }
      });
      addFilesToZip(out, files);

      // %USERDIR%
      File userPath = new File(SystemProperties.getUserPath());
      files = userPath.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
          return pathname.getName().endsWith(".log");
        }
      });
      addFilesToZip(out, files);

      // %USERDIR%\debug
      files = path.listFiles();
      addFilesToZip(out, files);

      // recent errors from exe dir
      final long ago = SystemTime.getCurrentTime() - 1000L * 60 * 60 * 24 * 90;
      File azureusPath = new File(SystemProperties.getApplicationPath());
      files = azureusPath.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
          return (pathname.getName().startsWith("hs_err") && pathname.lastModified() > ago);
        }
      });
      addFilesToZip(out, files);

      // recent errors from OSX java log dir
      File javaLogPath = new File(System.getProperty("user.home"), "Library"
          + File.separator + "Logs" + File.separator + "Java");
      if (javaLogPath.isDirectory()) {
        files = javaLogPath.listFiles(new FileFilter() {
          public boolean accept(File pathname) {
            return (pathname.getName().endsWith("log") && pathname.lastModified() > ago);
          }
        });
        addFilesToZip(out, files);
      }

      // recent OSX crashes
      File diagReportspath = new File(System.getProperty("user.home"), "Library"
          + File.separator + "Logs" + File.separator + "DiagnosticReports");
      if (diagReportspath.isDirectory()) {
        files = diagReportspath.listFiles(new FileFilter() {
          public boolean accept(File pathname) {
            return (pathname.getName().endsWith("crash") && pathname.lastModified() > ago);
          }
        });
        addFilesToZip(out, files);
      }

      boolean bLogToFile = COConfigurationManager.getBooleanParameter("Logging Enable");
      String sLogDir = COConfigurationManager.getStringParameter("Logging Dir",
          "");
      if (bLogToFile && sLogDir != null) {
        File loggingFile = new File(sLogDir, FileLogging.LOG_FILE_NAME);
        if (loggingFile.isFile()) {
          addFilesToZip(out, new File[] {
            loggingFile
          });
        }
      }

      if (extraLogDirs != null) {
        for (File file : extraLogDirs) {
          files = file.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
              return pathname.getName().endsWith("stackdump")
                  || pathname.getName().endsWith("log");
            }
          });
          addFilesToZip(out, files);
        }
      }

      out.close();

      if (outFile.exists()) {
        gr.file = outFile;
        return gr;
      }
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.