Package org.cdlib.mrt.utility
Class ArchiveBuilder
java.lang.Object
org.cdlib.mrt.utility.ArchiveBuilder
- Direct Known Subclasses:
ArchiveBuilder.Tar,ArchiveBuilder.Zip
Build an archive (tar, targz, or zip) from a directory
- Author:
- dloy
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumArchive types available Enum constructor: extension, mimeTypestatic classTar archive - with call backs for Tarstatic classTar-gunzip archive - with call backs specific to Tarstatic classZip archive - with call backs specific to zip -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ArchiveBuilder.ArchiveTypeprotected static final intprotected Fileprotected LoggerInfprotected static final Stringprotected static final Stringprotected OutputStreamprotected File -
Constructor Summary
ConstructorsConstructorDescriptionArchiveBuilder(File fromDir, File toArchive, LoggerInf logger, ArchiveBuilder.ArchiveType archiveType) Contructor used as build method for this classArchiveBuilder(File fromDir, OutputStream outputStream, LoggerInf logger, ArchiveBuilder.ArchiveType archiveType) Contructor used as build method for this class -
Method Summary
Modifier and TypeMethodDescriptionprotected voidRecursive method for finding files and adding to archiveprotected abstract voidaddItemFile(File entry, LoggerInf logger) Call back routinte to write an archive entry to archive output.protected voidCreate archive from constructor supplied valuesprotected abstract voidCall back routine to close archive.static ArchiveBuildergetArchiveBuilder(File fromDir, File toArchive, LoggerInf logger, ArchiveBuilder.ArchiveType archiveType) Factory routine to get specific ArchiveBuilder for supplied ArchiveTypestatic ArchiveBuildergetArchiveBuilder(File fromDir, OutputStream outputStream, LoggerInf logger, ArchiveBuilder.ArchiveType archiveType) Factory routine to get specific ArchiveBuilder for supplied ArchiveTypeprotected StringgetEntryName(File addFile) Normalize archive entry namestatic voidMain methodprotected voidsetEntry(OutputStream out, File entry) Move file to archiveprotected abstract voidsetOutputStream(OutputStream baseOutputStream) Call back routine for setting archive output stream type: tar, tar.gz, zip
-
Field Details
-
NAME
- See Also:
-
MESSAGE
- See Also:
-
BUFSIZE
protected static final int BUFSIZE- See Also:
-
archiveType
-
logger
-
fromDir
-
toArchive
-
outputStream
-
-
Constructor Details
-
ArchiveBuilder
public ArchiveBuilder(File fromDir, File toArchive, LoggerInf logger, ArchiveBuilder.ArchiveType archiveType) throws TException Contructor used as build method for this class- Parameters:
fromDir- - directory to be archivedtoArchive- - archive to this filelogger- - process loggingarchiveType- type of archive to create see ArchiveType- Throws:
TException
-
ArchiveBuilder
public ArchiveBuilder(File fromDir, OutputStream outputStream, LoggerInf logger, ArchiveBuilder.ArchiveType archiveType) throws TException Contructor used as build method for this class- Parameters:
fromDir- - directory to be archivedlogger- - process loggingarchiveType- type of archive to create see ArchiveTypetoArchive- - archive to this file- Throws:
TException
-
-
Method Details
-
getArchiveBuilder
public static ArchiveBuilder getArchiveBuilder(File fromDir, File toArchive, LoggerInf logger, ArchiveBuilder.ArchiveType archiveType) throws TException Factory routine to get specific ArchiveBuilder for supplied ArchiveType- Parameters:
fromDir- - directory to be archivedtoArchive- - archive to this filelogger- - process loggingarchiveType- type of archive to create see ArchiveType- Returns:
- specific type of ArchiveBuilder
- Throws:
TException
-
getArchiveBuilder
public static ArchiveBuilder getArchiveBuilder(File fromDir, OutputStream outputStream, LoggerInf logger, ArchiveBuilder.ArchiveType archiveType) throws TException Factory routine to get specific ArchiveBuilder for supplied ArchiveType- Parameters:
fromDir- - directory to be archivedlogger- - process loggingarchiveType- type of archive to create see ArchiveTypetoArchive- - archive to this file- Returns:
- specific type of ArchiveBuilder
- Throws:
TException
-
buildArchive
Create archive from constructor supplied values- Throws:
TException
-
setOutputStream
Call back routine for setting archive output stream type: tar, tar.gz, zip- Parameters:
baseOutputStream-- Throws:
TException
-
addItemFile
Call back routinte to write an archive entry to archive output. Archive type specific.- Parameters:
entry- archive file entry- Throws:
TException
-
closeArchive
protected abstract void closeArchive()Call back routine to close archive. Archive type specific. -
getEntryName
Normalize archive entry name- Parameters:
addFile- file used for generating archive name- Returns:
- normalized archive name
- Throws:
TException
-
addFiles
Recursive method for finding files and adding to archive- Parameters:
sourceLocation- file or directory to archive- Throws:
TException
-
setEntry
Move file to archive- Parameters:
out- write to this output streamentry- file to write to output- Throws:
TException
-
main
Main method
-