public class MultiZip extends Object
Some of the features of this classes implementation of archiving:
As you see this is a slightly different way of thinking of archiving - it provides maximum latitude in choosing the style a archive. For example: it allows the unconventional file.gz.tar format of an archive (all files are individually compressed with gzip format and then they are collected together into a tar archive format. Why??? its up to you. But this class should provide the way of getting the archive you want.
I personally bzip2 all my files into an empty directory which then is a staging area for making an iso-9660 image for backing onto a CDRW.
Usage details: (for full usage details...run MultiZip with no options)
java ca.bc.webarts.tools.MultiZip [options] <source directory(s)/file(s)> options: -a dir,tar,zip DEFAULT=zip -c none,zip,gzip,bzip2 DEFAULT=zip -l 0-9 DEFAULT=9 -v DEFAULT=not verbose -o filename DEFAULT=same as input location EXAMPLE: java MultiZip -a dir -c bzip2 -l 9 -o /home/joeBlo/staging /home/joBlo/src
This tool is released with a GNU General Public License.
Author: Tom Gutwin
tgutwin@webarts.bc.ca
Copyright © 2002 WebARTS Design.
Modifier and Type | Field and Description |
---|---|
(package private) int |
archivefilenameCounter_
Description of the Field
|
(package private) short |
archiveType_
The instatited archive type.
|
static short |
BZIP2_COMPRESSION
Constant VAR
|
protected static String |
className_
A Class holder for its name (used in Logging).
|
(package private) Vector |
compressedFilenames_
The collection of filenames that actually got comp'd.
|
(package private) int |
compressionLevel_
Description of the Field.
|
(package private) short |
compressionType_
Description of the Field.
|
(package private) long |
currArchiveSize_
The current archive file size in bytes.
|
(package private) String[] |
defaultExcludes_
Description of the Field
|
static short |
DIR_ARCHIVE
Constant VAR
|
(package private) Vector |
errorFiles_
The collection of filenames that had errors during compression.
|
static short |
GZIP_COMPRESSION
Constant VAR
|
(package private) Vector |
input_
The collection of files/dirnames to include in the archive.
|
static String |
LINE_SEPARATOR
Constant VAR
|
protected static String |
log4jConfigLocation_
The log4j logger config location.
|
protected static Logger |
logger_
The log4j logger object.
|
(package private) int |
maxArchiveSize_
The maximum size in megabytes the archive will be allowed to grow to
before creating a second archive with a incremental name.
|
static short |
NO_COMPRESSION
Constant VAR
|
(package private) String |
output_
The specified output filename/dirname.
|
protected boolean |
quiet_
Flags if the output will be reduced.
|
protected boolean |
reallyQuiet_
Flags for no output.
|
static short |
TAR_ARCHIVE
Constant VAR
|
static short |
TGZ_ARCHIVE
Constant VAR
|
private String |
tmpDirName_
The temp dir where the zipped files go before archiving.
|
protected boolean |
verbose_
Flags if the output will be verbose.
|
static short |
ZIP_ARCHIVE
Constant VAR
|
static short |
ZIP_COMPRESSION
Constant VAR
|
protected File |
zipfile_
The current working destination zip file.
|
(package private) String |
zippedOutputLocation_
The temp dir where the zipped files go before archiving.
|
protected DeflaterOutputStream |
zos_
Output stream for destination zip file.
|
Constructor and Description |
---|
MultiZip()
Default Constructor for the MultiZip object that does NO processing.
|
MultiZip(File[] src,
File des)
Constructor for the MultiZip object
|
MultiZip(File src,
File des)
Constructor for the MultiZip object
|
Modifier and Type | Method and Description |
---|---|
private short |
archiveFiles()
Executes the archiving of the input files.
|
long |
bzip2File(File source)
Encapsulates the bzip2ping of 1 file/dir in place.
|
long |
bzip2Files(File[] source)
Encapsulates the bzip2ping of file(s) individually in place.
|
long |
bzip2Files(Vector source)
Encapsulates the bzip2ping of file(s) individually in place.
|
private short |
compressFiles()
Executes the compression of the input files..
|
void |
copyFilesToArchive()
It simply copies the compressed files to the output dir for DIR type
archives.
|
void |
copyFileToArchive(File source)
It simply copies a compressed file to the output dir for DIR type archives
|
protected GZIPOutputStream |
createGZIPOutputStream(FileOutputStream fos)
Wraps the insantaition of a GZIPOutputStream.
|
protected ZipOutputStream |
createZipOutputStream(FileOutputStream fos)
Wraps the insantaition of a ZipOutputStream.
|
short |
doArchiving()
Initiates and begins the archival process.
|
protected boolean |
excludedFile(File fileToCheck)
Description of the Method
|
protected boolean |
excludedFile(String filename)
Description of the Method
|
short |
getArchiveType()
The public get method to return the archiveType_ class field.
|
int |
getCompressionLevel()
Gets the compressionLevel_ attribute of the MultiZip object
|
short |
getCompressionType()
The public get method to return the compressionType_ class field.
|
Vector |
getInput()
The public get method to return the input_ class field.
|
int |
getMaxArchiveSize()
Gets the maxArchiveSize_ attribute of the MultiZip object
|
String |
getOutput()
The public get method to return the output_ class field.
|
boolean |
getQuiet()
Gets the quiet_ field.
|
boolean |
getReallyQuiet()
The public get method to return the reallyQuiet_ class field.
|
boolean |
getVerbose()
The public get method to return the verbose_ class field.
|
String |
getZippedOutputLocation()
The public get method to return the zippedOutputLocation_ class field.
|
long |
gzipFile(File source)
Encapsulates the gzipping of 1 file/dir in place.
|
long |
gzipFiles(File[] source)
Encapsulates the gzipping of file(s) individually in place.
|
long |
gzipFiles(Vector source)
Encapsulates the gzipping of file(s) individually in place.
|
protected boolean |
initGZIPOutputStream(File destZipFile)
Creates a GZip type archive output stream and assigns it to the class
zipfile_ var.
|
protected boolean |
initZipOutputStream(File destZipFile)
Creates a Zip type archive output stream and assigns it to the class
zipfile_ var.
|
static void |
main(String[] args)
Main Entry point to run this class as an application usage:
MultiZip |
void |
moveFilesToArchive()
It simply moves all the compressed files to the output dir for DIR type
archives.
|
void |
moveFileToArchive(File source)
It simply move a compressed file to the output dir for DIR type archives.
|
private boolean |
oneStepArchive()
Examines the users Compression and Archive choices and looks for special
combos that require an adjustment in some settings.
|
private boolean |
oneStepCompress()
Examines the users Compression and Archive choices and looks for special
combos that require an adjustment in some settings.
|
private static void |
parseCmdArgs(String[] args,
MultiZip multiZipper)
Parses the cmd line args into usefule class vars.
|
private static void |
printUsage()
Parses the cmd line args into usefule class vars.
|
private Vector |
recurseInputIntoFiles(Vector input)
Runs through the input Vector and recurses any dirs into the contained
names.
|
long |
recursiveBzip2(File fo)
Wrapper method to accept a dir or individual file in the passed in File
object AND then calls the method that writes the passed file/dir to this
MultiZip instances zip output stream.
|
long |
recursiveGZip(File fo)
Wrapper method to accept a dir or individual file in the passed in File
object AND then calls the method that writes the passed file/dir to this
MultiZip instances zip output stream.
|
void |
recursiveZip(File fo)
Wrapper method to accept a dir or individual file in the passed in File
object AND then calls the method that writes the passed file/dir to this
MultiZip instances zip output stream.
|
void |
removeCompressedFiles()
It cleans up the compressed files by deleting them
|
void |
setArchiveType(short archiveType)
The public set method to set the archiveType_ class field.
|
void |
setArchiveType(String archiveType)
The public set method to set the compressionType_ class field.
|
void |
setCompressionLevel(int compressionLevel)
Sets the compressionLevel_ attribute of the MultiZip object
|
void |
setCompressionType(short compressionType)
The public set method to set the compressionType_ class field.
|
void |
setCompressionType(String compressionType)
The public set method to set the compressionType_ class field.
|
void |
setInput(String[] input)
The public set method to set the input_ class field.
|
void |
setInput(Vector input)
The public set method to set the input_ class field.
|
void |
setMaxArchiveSize(int maxArchiveSize)
Sets the maxArchiveSize_ attribute of the MultiZip object
|
void |
setOutput(String output)
The public set method to set the output_ class field.
|
void |
setQuiet(boolean quiet)
Sets the quiet_ field.
|
void |
setReallyQuiet(boolean reallyQuiet)
The public set method to set the reallyQuiet_ class field.
|
void |
setVerbose(boolean verbose)
The public set method to set the verbose_ class field.
|
void |
setZippedOutputLocation(String zippedOutputLocation)
The public set method to set the zippedOutputLocation_ class field.
|
boolean |
tarCompressedFilesDir(String outputTar)
Encapsulates the taring of the compressed Files dir into a TAR archive.
|
boolean |
tarFiles(String[] source,
String outputTar)
Encapsulates the taring of file(s) into a TAR archive.
|
boolean |
tarFiles(Vector source,
String outputTar)
Encapsulates the taring of file(s) into a TAR archive.
|
private boolean |
validateOutputLocation()
Using the class output_, compressionType_ and archiveType_, this method
validates that a valid and writable output location/file was specified.
|
long |
writeToGZip(File src)
Compresses and saves the passed file parameter to a gzip file.
|
long |
writeToGZip(File src,
String dest)
Compresses and saves the passed file parameter to a gzip file.
|
void |
writeToZip(File src)
Compresses and saves the passed file parameter to a zip file.
|
void |
zipFile(File source)
Encapsulates the zipping of 1 file individually in place.
|
void |
zipFile(File source,
File destination)
Encapsulates the zipping of an individual file into the specified
destination file.
|
void |
zipFiles(File[] source)
Encapsulates the zipping of file(s) individually into the class
zippedOutputLocation_.
|
void |
zipFiles(File[] source,
File destination)
Encapsulates the zipping of file(s) into a zip archive.
|
void |
zipFiles(Vector source)
Encapsulates the zipping of file(s) individually into the class
zippedOutputLocation_.
|
void |
zipFiles(Vector source,
File destination)
Encapsulates the zipping of file(s) into a zip archive.
|
public static final short DIR_ARCHIVE
public static final short TAR_ARCHIVE
public static final short ZIP_ARCHIVE
public static final short TGZ_ARCHIVE
public static final short ZIP_COMPRESSION
public static final short GZIP_COMPRESSION
public static final short BZIP2_COMPRESSION
public static final short NO_COMPRESSION
public static final String LINE_SEPARATOR
protected static String className_
protected static String log4jConfigLocation_
protected boolean verbose_
protected boolean quiet_
protected boolean reallyQuiet_
protected DeflaterOutputStream zos_
short archiveType_
short compressionType_
int compressionLevel_
String zippedOutputLocation_
Vector compressedFilenames_
Vector errorFiles_
int archivefilenameCounter_
int maxArchiveSize_
long currArchiveSize_
String[] defaultExcludes_
private String tmpDirName_
MultiZip()
MultiZip(File[] src, File des)
src
- An array of files to include in the zip.des
- Description of the Parameterpublic static void main(String[] args)
MultiZip
args
- 1st arg is the destination file, 2nd arg is the source filesprivate static void printUsage()
private static void parseCmdArgs(String[] args, MultiZip multiZipper)
args
- Description of the ParametermultiZipper
- Description of the Parameterpublic void setZippedOutputLocation(String zippedOutputLocation)
zippedOutputLocation
- is the value to use to set the class field
to.public String getZippedOutputLocation()
public void setInput(String[] input)
input
- is the value to use to set the class field to.public void setInput(Vector input)
input
- is the Vector of valuese to use to set the class field to.public Vector getInput()
public void setOutput(String output)
output
- The new output valuepublic String getOutput()
public void setCompressionType(String compressionType)
compressionType
- is the value to use to set the class field to.public void setCompressionType(short compressionType)
compressionType
- is the value to use to set the class field to.public short getCompressionType()
public void setArchiveType(String archiveType)
archiveType
- The new archiveType valuepublic void setArchiveType(short archiveType)
archiveType
- is the value to use to set the class field to.public short getArchiveType()
public void setReallyQuiet(boolean reallyQuiet)
reallyQuiet
- is the value to use to set the class field to.public boolean getReallyQuiet()
public void setVerbose(boolean verbose)
verbose
- is the value to use to set the class field to.public boolean getVerbose()
public boolean getQuiet()
public void setQuiet(boolean quiet)
quiet
- The new quiet_ valuepublic void setMaxArchiveSize(int maxArchiveSize)
maxArchiveSize
- The new maxArchiveSize valuepublic int getMaxArchiveSize()
public void setCompressionLevel(int compressionLevel)
compressionLevel
- The new compressionLevel_ valuepublic int getCompressionLevel()
public short doArchiving()
public void moveFileToArchive(File source)
source
- The filename to include in the archive.public void copyFileToArchive(File source)
source
- The filename to include in the archive.public void moveFilesToArchive()
public void copyFilesToArchive()
public void removeCompressedFiles()
public void zipFiles(Vector source)
source
- A Vector of Strings holding the filenames to include in the
zipped file.public long gzipFile(File source)
source
- The file to GZIP.public long gzipFiles(File[] source)
source
- The files to include in the zipped file.public long gzipFiles(Vector source)
source
- The filenames to include in the zipped file.public long bzip2Files(Vector source)
source
- The filenames to include in the zipped file.public long bzip2File(File source)
source
- The file to GZIP.public long bzip2Files(File[] source)
source
- The files to include in the zipped file.public void zipFile(File source, File destination)
source
- The files to include in the zipped file.destination
- The destination zip file location.public void zipFiles(File[] source)
source
- The files to include in the zipped file.public void zipFile(File source)
source
- The files to include in the zipped file.public void zipFiles(Vector source, File destination)
source
- A Vector of filenames to include in the zipped file.destination
- The resultant zipped archive.public void zipFiles(File[] source, File destination)
source
- The files to include in the zipped file.destination
- The resultant zipped archive.public boolean tarFiles(Vector source, String outputTar)
source
- A Vector of the filenames to include in the tar file.outputTar
- The tar filename.public boolean tarCompressedFilesDir(String outputTar)
outputTar
- The tar filename.public boolean tarFiles(String[] source, String outputTar)
source
- The files to include in the tar file.outputTar
- The tar filename.public long writeToGZip(File src) throws IOException
src
- The File to gzip up - it can be a dir.IOException
- Description of the Exceptionpublic long writeToGZip(File src, String dest) throws IOException
src
- The File to gzip up - it can be a dir.dest
- The location of the gzip'd file.IOException
- Description of the Exceptionpublic void writeToZip(File src) throws DataFormatException, ZipException, FileNotFoundException, IOException
src
- The File to zip up - it can be a dir.DataFormatException
- Description of the ExceptionZipException
- Description of the ExceptionFileNotFoundException
- Description of the ExceptionIOException
- Description of the Exceptionpublic long recursiveGZip(File fo)
fo
- The File object to zip up (can be an actual file or dir).public long recursiveBzip2(File fo)
fo
- The File object to zip up (can be an actual file or dir).public void recursiveZip(File fo)
fo
- The File object to zip up (can be an actual file or dir).protected boolean excludedFile(File fileToCheck)
fileToCheck
- Description of the Parameterprotected boolean excludedFile(String filename)
filename
- Description of the Parameterprotected GZIPOutputStream createGZIPOutputStream(FileOutputStream fos) throws IOException
fos
- Description of the ParameterIOException
- Description of the Exceptionprotected ZipOutputStream createZipOutputStream(FileOutputStream fos)
fos
- Description of the Parameterprotected boolean initGZIPOutputStream(File destZipFile)
destZipFile
- the base Zip filename (in File format) to createprotected boolean initZipOutputStream(File destZipFile)
destZipFile
- the base Zip filename (in File format) to createprivate boolean validateOutputLocation()
private Vector recurseInputIntoFiles(Vector input)
input
- Description of the Parameterprivate boolean oneStepArchive()
private boolean oneStepCompress()
private short compressFiles()
private short archiveFiles()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses