Package org.apache.commons.compress.archivers.zip

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream


  public long getSize(Map<String, byte[]> stringMap, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
    return -1;
  }

  public void writeTo(Map<String, byte[]> parts, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    ZipArchiveOutputStream zip = new ZipArchiveOutputStream(entityStream);

    zip.setMethod(ZipArchiveOutputStream.STORED);

    for (Map.Entry<String, byte[]> entry : parts.entrySet()) {
      zipStoreBuffer(zip, entry.getKey(), entry.getValue());
    }

    zip.close();
  }
View Full Code Here


  }

  public void createArchive()
  {
    // using commons compress to allow setting filename encoding pre java7
    ZipArchiveOutputStream out = null;
    try
    {
      collectFiles(baseDir, "");

      //make mimetype the first entry
      int mimetype = names.indexOf("mimetype");
      if (mimetype > -1)
      {
        String name = names.remove(mimetype);
        String path = paths.remove(mimetype);
        names.add(0, name);
        paths.add(0, path);
      }
      else
      {
        System.err.println("No mimetype file found in expanded publication, output archive will be invalid");
      }

      out = new ZipArchiveOutputStream(epubFile);
      out.setEncoding("UTF-8");

      for (int i = 0; i < paths.size(); i++)
      {
        ZipArchiveEntry entry = new ZipArchiveEntry(new File(paths.get(i)), names.get(i));
        if (i == 0 && mimetype > -1)
        {
          entry.setMethod(ZipArchiveEntry.STORED);
          entry.setSize(getSize(paths.get(i)));
          entry.setCrc(getCRC(paths.get(i)));
        }
        else
        {
          entry.setMethod(ZipArchiveEntry.DEFLATED);
        }
        out.putArchiveEntry(entry);
        FileInputStream in = null;
        try
        {
          in = new FileInputStream(paths.get(i));

          byte[] buf = new byte[1024];
          int len;
          while ((len = in.read(buf)) > 0)
          {
            out.write(buf, 0, len);
          }
          out.closeArchiveEntry();
        }
        finally
        {
          if (in != null)
          {
            in.close();
          }
        }
      }
    }
    catch (Exception e)
    {
      throw new RuntimeException(e.getMessage());
    }
    finally
    {
      try
      {
        if (out != null)
        {
          out.flush();
          out.finish();
          out.close();
        }
      }
      catch (IOException ignored)
      {
      }
View Full Code Here

   * @return the zipped file
   *
   * @throws IOException if an io exception occures
   */
  public File zip( @Nonnull File... directories ) throws IOException {
    ZipArchiveOutputStream outStream = new ZipArchiveOutputStream( new BufferedOutputStream( new FileOutputStream( zipFile ) ) );
    try {
      for ( File directory : directories ) {
        String baseName = directory.getCanonicalPath();
        addFiles( baseName, outStream, directory );
      }
    } finally {
      outStream.close();
    }
    return zipFile;
  }
View Full Code Here

        switch (archiveType){
            case TAR:
                aos = new TarArchiveOutputStream(new FileOutputStream(archiveFile), "UTF-8");
                ((TarArchiveOutputStream)aos).setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
                break;
            case ZIP: aos = new ZipArchiveOutputStream(new FileOutputStream(archiveFile)); break;
            default:
                throw new IOException("archive type not supported");
        }

        Deque<Entry> stack = new LinkedList<Entry>();
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream

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.