org.at4j.tar.builder
Class UstarEntryStrategy

java.lang.Object
  extended by org.at4j.tar.builder.V7TarEntryStrategy
      extended by org.at4j.tar.builder.UstarEntryStrategy
All Implemented Interfaces:
TarEntryStrategy
Direct Known Subclasses:
GnuTarEntryStrategy, PaxTarEntryStrategy

public class UstarEntryStrategy
extends V7TarEntryStrategy

This strategy extends the V7TarEntryStrategy to be able to write full ustar Tar entry headers. In addition to the data in a v7 header, the ustar header contains the following data:

Property Comment
Version of the ustar header This is set to 00
Owner name The name of the user owning the entity that the Tar entry was created from. The maximum size of this field is 31 8-byte characters.
Group name The name of the group owning the entity that the Tar entry was created from. The maximum size of this field is 31 8-byte characters.
Device major number This is always set to 0000000 by this implementation.
Device minor number This is always set to 0000000 by this implementation.
Name prefix This is 155 additional bytes that can be prefixed to the entry name if it is longer than 99 characters. This gives a theoretical maximum path length of 255 characters, but since the split must occur at a slash, the actual maximum length is often shorter.

Since:
1.0
Author:
Karl Gustafsson

Constructor Summary
UstarEntryStrategy()
          Create a new strategy object that will use the platform's default character encoding to encode text values in the Tar entries.
UstarEntryStrategy(Charset cs)
          Create a new strategy object that will use the supplied charset for encoding test values in the Tar entries.
 
Method Summary
protected  byte[] getHeader(Object entity, String fileName, TarEntrySettings effectiveSettings, long fileSize, EntityType entityType, Date lastModified)
          Override the inherited implementation to add ustar specific data.
protected  void setFileNameInHeader(byte[] header, String fileName)
          Override the inherited implementation to be able to split long file names between the prefix and the name fields.
 
Methods inherited from class org.at4j.tar.builder.V7TarEntryStrategy
addChecksumToHeader, getFileName, getTextEncodingCharset, goToNextBlockBoundary, writeDirectory, writeFile, writeFileFromStream, writeFileToArchive, zeroPadLeft
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UstarEntryStrategy

public UstarEntryStrategy()
Create a new strategy object that will use the platform's default character encoding to encode text values in the Tar entries.

See Also:
UstarEntryStrategy(Charset)

UstarEntryStrategy

public UstarEntryStrategy(Charset cs)
Create a new strategy object that will use the supplied charset for encoding test values in the Tar entries.

Parameters:
cs - The charset.
See Also:
UstarEntryStrategy()
Method Detail

setFileNameInHeader

protected void setFileNameInHeader(byte[] header,
                                   String fileName)
                            throws ArchiveEntryAddException
Override the inherited implementation to be able to split long file names between the prefix and the name fields.

Overrides:
setFileNameInHeader in class V7TarEntryStrategy
Parameters:
header - The header to add the file name to.
fileName - The file name to add.
Throws:
ArchiveEntryAddException - If the file name is too long.

getHeader

protected byte[] getHeader(Object entity,
                           String fileName,
                           TarEntrySettings effectiveSettings,
                           long fileSize,
                           EntityType entityType,
                           Date lastModified)
                    throws ArchiveEntryAddException
Override the inherited implementation to add ustar specific data.

Overrides:
getHeader in class V7TarEntryStrategy
Parameters:
entity - The entity that the Tar entry should represent. This may be a file, a directory or an InputStream.
fileName - The name of the entity.
effectiveSettings - Effective settings for the entry.
fileSize - If the entry is a file entry, this value contains the file size in bytes.
entityType - The type of the entity being added.
lastModified - When the entity was last modified.
Returns:
A 512 byte long array, without the checksum field filled in. The V7TarEntryStrategy.addChecksumToHeader(byte[]) method may be used to calculate the header's checksum when all data has been added to it.
Throws:
ArchiveEntryAddException - If the entry cannot be created, for some reason.