eu.cedarsoft.utils
Class ZipCreator

java.lang.Object
  extended by eu.cedarsoft.utils.ZipCreator

public class ZipCreator
extends java.lang.Object

Helper class that creates zip files


Constructor Summary
ZipCreator(java.io.File zipFile)
          Create a new zip creator with the given file as backend
 
Method Summary
protected  void addFiles(java.lang.String baseName, java.util.zip.ZipOutputStream outStream, java.io.File directory)
          Add the files within the given directory to the ZipOutputStream.
protected static java.lang.String getRelativePath(java.lang.String baseName, java.io.File file)
          Returns the relative path
 java.io.File getZipFile()
          Returns the zip file
 java.io.File zip(java.io.File... directories)
          Zip all files within the given directories
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipCreator

public ZipCreator(@NotNull
                  java.io.File zipFile)
Create a new zip creator with the given file as backend

Parameters:
zipFile - the zip file
Method Detail

getZipFile

@NotNull
public java.io.File getZipFile()
Returns the zip file

Returns:
the zip file

zip

public java.io.File zip(@NotNull
                        java.io.File... directories)
                 throws java.io.IOException
Zip all files within the given directories

Parameters:
directories - the directories all files are zipped within
Returns:
the zipped file
Throws:
java.io.IOException - if an io exception occures

addFiles

protected void addFiles(@NotNull
                        java.lang.String baseName,
                        @NotNull
                        java.util.zip.ZipOutputStream outStream,
                        @NotNull
                        java.io.File directory)
                 throws java.io.IOException
Add the files within the given directory to the ZipOutputStream. This method will call itself for each subdirectory.

Parameters:
baseName - represents the relative base name within the zip file
outStream - the ouput stream
directory - the directory
Throws:
java.io.IOException

getRelativePath

@NotNull
protected static java.lang.String getRelativePath(@NotNull
                                                          java.lang.String baseName,
                                                          @NotNull
                                                          java.io.File file)
                                           throws java.io.IOException
Returns the relative path

Parameters:
baseName - the base path
file - the file
Returns:
the path of the given file relative to the base name
Throws:
java.io.IOException


Copyright © 2007 Cedarsoft. All Rights Reserved.