SORTIE Java Interface  1
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
sortie.fileops.TarArchive Class Reference

The TarArchive class implements the concept of a tar archive. More...

Inheritance diagram for sortie.fileops.TarArchive:

Public Member Functions

 TarArchive (InputStream inStream)
 The InputStream based constructors create a TarArchive for the purposes of e'x'tracting or lis't'ing a tar archive. More...
 
 TarArchive (InputStream inStream, int blockSize)
 
 TarArchive (InputStream inStream, int blockSize, int recordSize)
 
 TarArchive (OutputStream outStream)
 The OutputStream based constructors create a TarArchive for the purposes of 'c'reating a tar archive. More...
 
 TarArchive (OutputStream outStream, int blockSize)
 
 TarArchive (OutputStream outStream, int blockSize, int recordSize)
 
void setDebug (boolean debugF)
 Set the debugging flag. More...
 
boolean isVerbose ()
 Returns the verbosity setting. More...
 
void setVerbose (boolean verbose)
 Set the verbosity flag. More...
 
void setTarProgressDisplay (TarProgressDisplay display)
 Set the current progress display interface. More...
 
void setKeepOldFiles (boolean keepOldFiles)
 Set the flag that determines whether existing files are kept, or overwritten during extraction. More...
 
void setAsciiTranslation (boolean asciiTranslate)
 Set the ascii file translation flag. More...
 
void setTransFileTyper (TarTransFileTyper transTyper)
 Set the object that will determine if a file is of type ascii text for translation purposes. More...
 
void setUserInfo (int userId, String userName, int groupId, String groupName)
 Set user and group information that will be used to fill in the tar archive's entry headers. More...
 
int getUserId ()
 Get the user id being used for archive entry headers. More...
 
String getUserName ()
 Get the user name being used for archive entry headers. More...
 
int getGroupId ()
 Get the group id being used for archive entry headers. More...
 
String getGroupName ()
 Get the group name being used for archive entry headers. More...
 
String getTempDirectory ()
 Get the current temporary directory path. More...
 
void setTempDirectory (String path)
 Set the current temporary directory path. More...
 
int getRecordSize ()
 Get the archive's record size. More...
 
void closeArchive () throws IOException
 Close the archive. More...
 
void listContents () throws IOException, InvalidHeaderException
 Perform the "list" command and list the contents of the archive. More...
 
ArrayList< String > listContentsAsString () throws IOException, InvalidHeaderException
 Perform the "list" command and list the contents of the archive. More...
 
void extractContents (File destDir) throws IOException, InvalidHeaderException
 Perform the "extract" command and extract the contents of the archive. More...
 
void extractContentsNoPath (File destDir) throws IOException, InvalidHeaderException
 Perform the "extract" command and extract the contents of the archive. More...
 
String extractFile (File destDir, String sName) throws IOException
 Extracts a single entry by searching for it by name. More...
 
String extractFileNoPath (File destDir, String sName) throws IOException
 Extracts a single entry by searching for it by name. More...
 
String getPath () throws IOException
 Gets the path info for this archive. More...
 
void writeEntry (TarEntry oldEntry, boolean recurse) throws IOException
 Write an entry to the archive. More...
 

Protected Attributes

boolean verbose
 
boolean debug
 
boolean keepOldFiles
 
boolean asciiTranslate
 
int userId
 
String userName
 
int groupId
 
String groupName
 
String rootPath
 
String tempPath
 
String pathPrefix
 
int recordSize
 
byte [] recordBuf
 
TarInputStream tarIn
 
TarOutputStream tarOut
 
TarTransFileTyper transTyper
 
TarProgressDisplay progressDisplay
 

Private Member Functions

void initialize (int recordSize)
 Common constructor initialization code. More...
 
String getTempFilePath (File eFile)
 Get a path for a temporary file for a given File. More...
 
void extractEntry (File destDir, TarEntry entry, String sName) throws IOException
 Extract an entry from the archive. More...
 
String extractHeaderEntry (TarEntry entry) throws IOException
 Extract a header entry from the archive and read its contents. More...
 

Detailed Description

The TarArchive class implements the concept of a tar archive.

A tar archive is a series of entries, each of which represents a file system object. Each entry in the archive consists of a header record. Directory entries consist only of the header record, and are followed by entries for the directory's contents. File entries consist of a header record followed by the number of records needed to contain the file's contents. All entries are written on record boundaries. Records are 512 bytes long.

TarArchives are instantiated in either read or write mode, based upon whether they are instantiated with an InputStream or an OutputStream. Once instantiated TarArchives read/write mode can not be changed.

There is currently no support for random access to tar archives. However, it seems that subclassing TarArchive, and using the TarBuffer.getCurrentRecordNum() and TarBuffer.getCurrentBlockNum() methods, this would be rather trvial.

LEM: I modified this file, which otherwise works extremely well, to be able to deal with the fact that older versions of TAR can't handle long file names. Instead, the tar entry header's name is just ././@longlink, and there is an extra entry inserted with the actual filename. This watches for this problem and works around it during extraction.

Version
Revision
1.15
Author
Timothy Gerard Endres, time@.nosp@m.gjt..nosp@m.org
See also
TarBuffer
TarHeader
TarEntry

Constructor & Destructor Documentation

◆ TarArchive() [1/6]

sortie.fileops.TarArchive.TarArchive ( InputStream  inStream)

The InputStream based constructors create a TarArchive for the purposes of e'x'tracting or lis't'ing a tar archive.

Thus, use these constructors when you wish to extract files from or list the contents of an existing tar archive.

◆ TarArchive() [2/6]

sortie.fileops.TarArchive.TarArchive ( InputStream  inStream,
int  blockSize 
)

◆ TarArchive() [3/6]

sortie.fileops.TarArchive.TarArchive ( InputStream  inStream,
int  blockSize,
int  recordSize 
)

◆ TarArchive() [4/6]

sortie.fileops.TarArchive.TarArchive ( OutputStream  outStream)

The OutputStream based constructors create a TarArchive for the purposes of 'c'reating a tar archive.

Thus, use these constructors when you wish to create a new tar archive and write files into it.

◆ TarArchive() [5/6]

sortie.fileops.TarArchive.TarArchive ( OutputStream  outStream,
int  blockSize 
)

◆ TarArchive() [6/6]

sortie.fileops.TarArchive.TarArchive ( OutputStream  outStream,
int  blockSize,
int  recordSize 
)

Member Function Documentation

◆ closeArchive()

void sortie.fileops.TarArchive.closeArchive ( ) throws IOException

Close the archive.

This simply calls the underlying tar stream's close() method.

◆ extractContents()

void sortie.fileops.TarArchive.extractContents ( File  destDir) throws IOException, InvalidHeaderException

Perform the "extract" command and extract the contents of the archive.

Parameters
destDirThe destination directory into which to extract.

◆ extractContentsNoPath()

void sortie.fileops.TarArchive.extractContentsNoPath ( File  destDir) throws IOException, InvalidHeaderException

Perform the "extract" command and extract the contents of the archive.

This will suppress internal directories in the tar archive.

Parameters
destDirThe destination directory into which to extract.

◆ extractEntry()

void sortie.fileops.TarArchive.extractEntry ( File  destDir,
TarEntry  entry,
String  sName 
) throws IOException
private

Extract an entry from the archive.

This method assumes that the tarIn stream has been properly set with a call to getNextEntry().

LEM: Added the sName parameter - this is what the extracted file will be named at all times.

Parameters
destDirThe destination directory into which to extract.
entryThe TarEntry returned by tarIn.getNextEntry().
sNameThe name to extract to.

◆ extractFile()

String sortie.fileops.TarArchive.extractFile ( File  destDir,
String  sName 
) throws IOException

Extracts a single entry by searching for it by name.

The name doesn't have to match exactly (in case the path info is not present). The first entry that completely contains the entry's name string will be extracted.

Parameters
destDirThe destination directory into which to extract.
sNameThe name of the entry.
Returns
Name of file extracted.
Exceptions
java.io.IOExceptionif there is a problem writing the file.

◆ extractFileNoPath()

String sortie.fileops.TarArchive.extractFileNoPath ( File  destDir,
String  sName 
) throws IOException

Extracts a single entry by searching for it by name.

The name doesn't have to match exactly (in case the path info is not present). The first entry that completely contains the entry's name string will be extracted.

Parameters
destDirThe destination directory into which to extract.
sNameThe name of the entry.
Returns
Name of file extracted.
Exceptions
java.io.IOExceptionif there is a problem writing the file.

◆ extractHeaderEntry()

String sortie.fileops.TarArchive.extractHeaderEntry ( TarEntry  entry) throws IOException
private

Extract a header entry from the archive and read its contents.

This method assumes that the tarIn stream has been properly set with a call to getNextEntry(), and that the next entry is in fact a text string. This doesn't have the good error checking normally in place in this library.

Created this to circumvent the need to write out and read back in the header string.

Author
Lora Murphy
Parameters
entryThe TarEntry returned by tarIn.getNextEntry().

◆ getGroupId()

int sortie.fileops.TarArchive.getGroupId ( )

Get the group id being used for archive entry headers.

Returns
The current group id.

◆ getGroupName()

String sortie.fileops.TarArchive.getGroupName ( )

Get the group name being used for archive entry headers.

Returns
The current group name.

◆ getPath()

String sortie.fileops.TarArchive.getPath ( ) throws IOException

Gets the path info for this archive.

@longlink safe.

Returns
Path info for this archive.
Author
Lora Murphy

◆ getRecordSize()

int sortie.fileops.TarArchive.getRecordSize ( )

Get the archive's record size.

Because of its history, tar supports the concept of buffered IO consisting of BLOCKS of RECORDS. This allowed tar to match the IO characteristics of the physical device being used. Of course, in the Java world, this makes no sense, WITH ONE EXCEPTION - archives are expected to be propertly "blocked". Thus, all of the horrible TarBuffer support boils down to simply getting the "boundaries" correct.

Returns
The record size this archive is using.

◆ getTempDirectory()

String sortie.fileops.TarArchive.getTempDirectory ( )

Get the current temporary directory path.

Because Java's File did not support temporary files until version 1.2, TarArchive manages its own concept of the temporary directory. The temporary directory defaults to the 'user.dir' System property.

Returns
The current temporary directory path.

◆ getTempFilePath()

String sortie.fileops.TarArchive.getTempFilePath ( File  eFile)
private

Get a path for a temporary file for a given File.

The temporary file is NOT created. The algorithm attempts to handle filename collisions so that the name is unique.

Returns
The temporary file's path.

◆ getUserId()

int sortie.fileops.TarArchive.getUserId ( )

Get the user id being used for archive entry headers.

Returns
The current user id.

◆ getUserName()

String sortie.fileops.TarArchive.getUserName ( )

Get the user name being used for archive entry headers.

Returns
The current user name.

◆ initialize()

void sortie.fileops.TarArchive.initialize ( int  recordSize)
private

Common constructor initialization code.

◆ isVerbose()

boolean sortie.fileops.TarArchive.isVerbose ( )

Returns the verbosity setting.

Returns
The current verbosity setting.

◆ listContents()

void sortie.fileops.TarArchive.listContents ( ) throws IOException, InvalidHeaderException

Perform the "list" command and list the contents of the archive.

NOTE That this method uses the progress display to actually list the conents. If the progress display is not set, nothing will be listed!

◆ listContentsAsString()

ArrayList<String> sortie.fileops.TarArchive.listContentsAsString ( ) throws IOException, InvalidHeaderException

Perform the "list" command and list the contents of the archive.

This returns the headers as actual strings. This is @longlink safe.

Author
Lora Murphy.

◆ setAsciiTranslation()

void sortie.fileops.TarArchive.setAsciiTranslation ( boolean  asciiTranslate)

Set the ascii file translation flag.

If ascii file translatio is true, then the MIME file type will be consulted to determine if the file is of type 'text/*'. If the MIME type is not found, then the TransFileTyper is consulted if it is not null. If either of these two checks indicates the file is an ascii text file, it will be translated. The translation converts the local operating system's concept of line ends into the UNIX line end, '
', which is the defacto standard for a TAR archive. This makes text files compatible with UNIX, and since most tar implementations for other platforms, compatible with most other platforms.

Parameters
asciiTranslateIf true, translate ascii text files.

◆ setDebug()

void sortie.fileops.TarArchive.setDebug ( boolean  debugF)

Set the debugging flag.

Parameters
debugFThe new debug setting.

◆ setKeepOldFiles()

void sortie.fileops.TarArchive.setKeepOldFiles ( boolean  keepOldFiles)

Set the flag that determines whether existing files are kept, or overwritten during extraction.

Parameters
keepOldFilesIf true, do not overwrite existing files.

◆ setTarProgressDisplay()

void sortie.fileops.TarArchive.setTarProgressDisplay ( TarProgressDisplay  display)

Set the current progress display interface.

This allows the programmer to use a custom class to display the progress of the archive's processing.

Parameters
displayThe new progress display interface.
See also
TarProgressDisplay

◆ setTempDirectory()

void sortie.fileops.TarArchive.setTempDirectory ( String  path)

Set the current temporary directory path.

Parameters
pathThe new temporary directory path.

◆ setTransFileTyper()

void sortie.fileops.TarArchive.setTransFileTyper ( TarTransFileTyper  transTyper)

Set the object that will determine if a file is of type ascii text for translation purposes.

Parameters
transTyperThe new TransFileTyper object.

◆ setUserInfo()

void sortie.fileops.TarArchive.setUserInfo ( int  userId,
String  userName,
int  groupId,
String  groupName 
)

Set user and group information that will be used to fill in the tar archive's entry headers.

Since Java currently provides no means of determining a user name, user id, group name, or group id for a given File, TarArchive allows the programmer to specify values to be used in their place.

Parameters
userIdThe user Id to use in the headers.
userNameThe user name to use in the headers.
groupIdThe group id to use in the headers.
groupNameThe group name to use in the headers.

◆ setVerbose()

void sortie.fileops.TarArchive.setVerbose ( boolean  verbose)

Set the verbosity flag.

Parameters
verboseThe new verbosity setting.

◆ writeEntry()

void sortie.fileops.TarArchive.writeEntry ( TarEntry  oldEntry,
boolean  recurse 
) throws IOException

Write an entry to the archive.

This method will call the putNextEntry() and then write the contents of the entry, and finally call closeEntry() for entries that are files. For directories, it will call putNextEntry(), and then, if the recurse flag is true, process each entry that is a child of the directory.

Parameters
oldEntryThe TarEntry representing the entry to write to the archive.
recurseIf true, process the children of directory entries.

Member Data Documentation

◆ asciiTranslate

boolean sortie.fileops.TarArchive.asciiTranslate
protected

◆ debug

boolean sortie.fileops.TarArchive.debug
protected

◆ groupId

int sortie.fileops.TarArchive.groupId
protected

◆ groupName

String sortie.fileops.TarArchive.groupName
protected

◆ keepOldFiles

boolean sortie.fileops.TarArchive.keepOldFiles
protected

◆ pathPrefix

String sortie.fileops.TarArchive.pathPrefix
protected

◆ progressDisplay

TarProgressDisplay sortie.fileops.TarArchive.progressDisplay
protected

◆ recordBuf

byte [] sortie.fileops.TarArchive.recordBuf
protected

◆ recordSize

int sortie.fileops.TarArchive.recordSize
protected

◆ rootPath

String sortie.fileops.TarArchive.rootPath
protected

◆ tarIn

TarInputStream sortie.fileops.TarArchive.tarIn
protected

◆ tarOut

TarOutputStream sortie.fileops.TarArchive.tarOut
protected

◆ tempPath

String sortie.fileops.TarArchive.tempPath
protected

◆ transTyper

TarTransFileTyper sortie.fileops.TarArchive.transTyper
protected

◆ userId

int sortie.fileops.TarArchive.userId
protected

◆ userName

String sortie.fileops.TarArchive.userName
protected

◆ verbose

boolean sortie.fileops.TarArchive.verbose
protected

The documentation for this class was generated from the following file: