com.threerings.jpkg
Class PackageTarFile

java.lang.Object
  extended by com.threerings.jpkg.PackageTarFile
All Implemented Interfaces:
ArchiveEntry

public class PackageTarFile
extends Object
implements ArchiveEntry

A wrapper around TarOutputStream to handle adding files from a destroot into a tar file. Every regular file will have its md5 checksum recorded and the total amount of file data in kilobytes will be stored.


Constructor Summary
PackageTarFile(File safeTemp)
          Convenience constructor to create PackageTarFile with an empty PermissionsMap.
PackageTarFile(File safeTemp, PermissionsMap permissions)
          Initialize a PackageTar file.
 
Method Summary
 void addDirectory(File directory)
          Add the contents of the supplied directory to the tar file.
 void addFile(File file)
          Add directories and files to the tar archive without stripping a leading path.
 void addFile(File file, String stripPath)
          Add directories and files to the tar archive.
 void close()
          Closes the tar file.
 boolean delete()
          Deletes the tar file.
 int getGroupId()
          Returns the group id which will own this entry in the archive.
 InputStream getInputStream()
          Returns an InputStream from the data contained in this entry.
 Map<String,String> getMd5s()
          Return the map of tar entry paths to md5 checksums for regular files added to this tar file.
 int getMode()
          Returns the file permissions mode (e.g.
 String getPath()
          Returns the path name used to identify this entry in the archive.
 long getSize()
          Returns the size of the data contained in this entry in bytes.
 long getTotalDataSize()
          Return the total amount of file data added to this tar file, in kilobytes.
 int getUserId()
          Returns the user id which will own this entry in the archive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackageTarFile

public PackageTarFile(File safeTemp)
               throws IOException
Convenience constructor to create PackageTarFile with an empty PermissionsMap.

Throws:
IOException
See Also:
PackageTarFile(File, PermissionsMap)

PackageTarFile

public PackageTarFile(File safeTemp,
                      PermissionsMap permissions)
               throws IOException
Initialize a PackageTar file.

Parameters:
safeTemp - A location with enough free space to hold the tar data.
permissions - A PermissionsMap will be used to manipulate entries before being added to the tar file.
Throws:
IOException - If the tar file cannot be initialized due to i/o errors.
Method Detail

addDirectory

public void addDirectory(File directory)
                  throws IOException
Add the contents of the supplied directory to the tar file. The root of the directory path will be stripped from all entries being added to the tar file. e.g. If /root is supplied: /root/directory/file.txt -> directory/file.txt

Throws:
IOException

addFile

public void addFile(File file)
             throws DuplicatePermissionsException,
                    IOException
Add directories and files to the tar archive without stripping a leading path.

Throws:
DuplicatePermissionsException
IOException
See Also:
addFile(File, String)

addFile

public void addFile(File file,
                    String stripPath)
             throws DuplicatePermissionsException,
                    IOException
Add directories and files to the tar archive. All file paths are treated as absolute paths.

Parameters:
file - The File to add to the tar archive.
stripPath - The path to stripped from the start of any entry path before adding it to the tar file.
Throws:
InvalidPathException - If the supplied stripPath path cannot be normalized.
DuplicatePermissionsException - If more than one permission in the defined PermissionsMap maps to the file being added.
IOException - If any i/o exceptions occur when appending the file data.

close

public void close()
           throws IOException
Closes the tar file. This must be called to create a valid tar file.

Throws:
IOException

delete

public boolean delete()
Deletes the tar file. Returns true if the file was deleted, false otherwise.


getMd5s

public Map<String,String> getMd5s()
Return the map of tar entry paths to md5 checksums for regular files added to this tar file.


getTotalDataSize

public long getTotalDataSize()
Return the total amount of file data added to this tar file, in kilobytes. If the supplied data is less than a kilobyte, 1 is returned.


getInputStream

public InputStream getInputStream()
                           throws IOException
Description copied from interface: ArchiveEntry
Returns an InputStream from the data contained in this entry.

Specified by:
getInputStream in interface ArchiveEntry
Throws:
IOException

getSize

public long getSize()
Description copied from interface: ArchiveEntry
Returns the size of the data contained in this entry in bytes. An Archive can only store data whose size can be expressed in a 32 bit integer however the interface allows size to be expressed as a long to support for example File objects. The Archive class will guarantee that the size returned by this method can be converted safely into a 32 bit integer.

Specified by:
getSize in interface ArchiveEntry

getPath

public String getPath()
Description copied from interface: ArchiveEntry
Returns the path name used to identify this entry in the archive. Must be 15 characters or less.

Specified by:
getPath in interface ArchiveEntry

getUserId

public int getUserId()
Description copied from interface: ArchiveEntry
Returns the user id which will own this entry in the archive.

Specified by:
getUserId in interface ArchiveEntry

getGroupId

public int getGroupId()
Description copied from interface: ArchiveEntry
Returns the group id which will own this entry in the archive.

Specified by:
getGroupId in interface ArchiveEntry

getMode

public int getMode()
Description copied from interface: ArchiveEntry
Returns the file permissions mode (e.g. 0644) for this entry in the archive.

Specified by:
getMode in interface ArchiveEntry


Copyright © 2007-2008 Three Rings Design, Inc. All Rights Reserved. Released under a BSD license.