com.atlassian.core.util.zip
Class ZipArchiver

java.lang.Object
  extended by com.atlassian.core.util.zip.ZipArchiver

@NotThreadSafe
public class ZipArchiver
extends Object

An utility class which allows to add multiple directories/files/entries from stream to zip archive.

Since:
v6.4

Constructor Summary
ZipArchiver(File archiveFile)
           
 
Method Summary
 void addEntry(InputStream content, String entryPath)
          Adds new entry to zip archive with name specified by entryPath parameter and with content from provided InputStream
 void addFile(File sourceFile, String targetPath)
          Adds a file to archive.
 void addFolder(File folderToCompress, ArchiveParams archiveParams)
          Adds directory and all subdirectories into archive.
 void addFolder(File folderToCompress, String archiveFolderName)
          Adds directory and all subdirectories into archive.
 OutputStream addNextEntry(String entryName)
          Creates new zipEntry and provides OutputStream to write content to given entry.
 void close()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipArchiver

public ZipArchiver(File archiveFile)
Method Detail

addFolder

public void addFolder(File folderToCompress,
                      String archiveFolderName)
               throws IOException
Adds directory and all subdirectories into archive.

Parameters:
folderToCompress - the directory handle to add to archive
archiveFolderName - the name which will be used as archive directory name, for example when folderToCompress is pointing into /home/A/B directory which contains file with path /home/A/B/C/file and archiveFolderName equals "archive" a result zip archive will contain entry: /archive/C/file
Throws:
IOException

addFolder

public void addFolder(File folderToCompress,
                      ArchiveParams archiveParams)
               throws IOException
Adds directory and all subdirectories into archive.

Parameters:
folderToCompress - the directory handle to add to archive
archiveParams - parameters for the files in the folder to be added the to archive
Throws:
IOException

addFile

public void addFile(File sourceFile,
                    String targetPath)
             throws IOException
Adds a file to archive.

Parameters:
sourceFile - a file which content will be added as new entry
targetPath - a file path which will be used as entry name
Throws:
IOException

addEntry

public void addEntry(InputStream content,
                     String entryPath)
              throws IOException
Adds new entry to zip archive with name specified by entryPath parameter and with content from provided InputStream

Parameters:
content - stream which will be used as entry content
entryPath - will be used as entry name
Throws:
IOException

addNextEntry

public OutputStream addNextEntry(String entryName)
                          throws IOException
Creates new zipEntry and provides OutputStream to write content to given entry. Keep in mind that provided outPutStream is valid as long as no other methods creating new entry are called.

Parameters:
entryName - the name of zip entry
Returns:
OutputStream to write content to given entry
Throws:
IOException

close

public void close()
           throws IOException
Throws:
IOException


Copyright © 2015 Atlassian. All rights reserved.