org.at4j.tar.builder
Class PaxTarEntryStrategy

java.lang.Object
  extended by org.at4j.tar.builder.V7TarEntryStrategy
      extended by org.at4j.tar.builder.UstarEntryStrategy
          extended by org.at4j.tar.builder.PaxTarEntryStrategy
All Implemented Interfaces:
TarEntryStrategy

public class PaxTarEntryStrategy
extends UstarEntryStrategy

This strategy extends the UstarEntryStrategy creates a special Pax header before the regular ustar header. The Pax header contains metadata variables. Pax variables are always encoded in UTF-8 in the Tar file, which should make them (the only part of the Tar file that is) portable across different platforms.

If the Tar entry path is too long to fit in the regular ustar header, the full path is set in the Pax header variable "path" and a truncated path is used in the ustar header.

If it is detected that the path name of the entry contains non-ASCII characters, the "path" variable is added even if the path name is short enough to fit in the ustar header.

By default, this strategy adds the "mtime" (last entity modification time) and perhaps the "path" Pax variables to the headers that it creates. By adding PaxVariableProvider objects to the strategy, more variables can be set.

Since:
1.0
Author:
Karl Gustafsson

Constructor Summary
PaxTarEntryStrategy()
          Create a new strategy object that will use the platform's default character encoding to encode text values in the Tar entries.
PaxTarEntryStrategy(Charset cs)
          Create a new strategy object that will use the supplied charset for encoding test values in the Tar entries.
 
Method Summary
 PaxTarEntryStrategy addPaxVariableProvider(PaxVariableProvider p)
          Add one Pax variable provider.
 int getProcessId()
          Get the process id.
 PaxTarEntryStrategy setProcessId(int processId)
          Set the process id of the current process (optional).
 void writeDirectory(DataSink out, DirectoryAdapter<?> da, AbsoluteLocation location, TarEntrySettings effectiveSettings, Date lastModified)
          Override the inherited implementation to add a Pax header before the ustar header.
 void writeFile(DataSink out, ReadableFile f, AbsoluteLocation location, TarEntrySettings effectiveSettings, Date lastModified)
          Override the inherited implementation to add a Pax header before the ustar header.
 void writeFileFromStream(RandomAccess out, InputStream is, AbsoluteLocation location, TarEntrySettings effectiveSettings, Date lastModified)
          Override the inherited implementation to add a Pax header before the ustar header.
 
Methods inherited from class org.at4j.tar.builder.UstarEntryStrategy
getHeader, setFileNameInHeader
 
Methods inherited from class org.at4j.tar.builder.V7TarEntryStrategy
addChecksumToHeader, getFileName, getTextEncodingCharset, goToNextBlockBoundary, writeFileToArchive, zeroPadLeft
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PaxTarEntryStrategy

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

See Also:
PaxTarEntryStrategy(Charset)

PaxTarEntryStrategy

public PaxTarEntryStrategy(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:
PaxTarEntryStrategy()
Method Detail

setProcessId

public PaxTarEntryStrategy setProcessId(int processId)
                                 throws IllegalArgumentException
Set the process id of the current process (optional). The process id is used when creating the name of the Pax header. If this is not set, a default process id of 1000 is used. (There are no good platform-independent ways of discovering a Java process' process id.)

Parameters:
processId - The process id.
Returns:
this
Throws:
IllegalArgumentException - If the process id is zero or negative.

getProcessId

public int getProcessId()
Get the process id.

Returns:
The process id.
See Also:
setProcessId(int)

addPaxVariableProvider

public PaxTarEntryStrategy addPaxVariableProvider(PaxVariableProvider p)
Add one Pax variable provider.

Parameters:
p - A Pax variable provider.
Returns:
this

writeFile

public void writeFile(DataSink out,
                      ReadableFile f,
                      AbsoluteLocation location,
                      TarEntrySettings effectiveSettings,
                      Date lastModified)
Override the inherited implementation to add a Pax header before the ustar header.

Specified by:
writeFile in interface TarEntryStrategy
Overrides:
writeFile in class V7TarEntryStrategy
Parameters:
out - The DataSink to write to. This may be a RandomAccess object. When this method is called, the DataSink is positioned at the start of the entry to write. If this method returns successfully, the DataSink should be positioned at the next block boundary after the written entry (the Tar file is divided into 512-byte blocks).
f - The file to add to the archive. If this file is in a locking FileSystem, it is locked for reading by the caller before this method is called.
location - The absolute location of the entry in the Tar archive.
effectiveSettings - The effective settings for the entry.
lastModified - The time when the file entity was last modified.

writeFileFromStream

public void writeFileFromStream(RandomAccess out,
                                InputStream is,
                                AbsoluteLocation location,
                                TarEntrySettings effectiveSettings,
                                Date lastModified)
Override the inherited implementation to add a Pax header before the ustar header.

Specified by:
writeFileFromStream in interface TarEntryStrategy
Overrides:
writeFileFromStream in class V7TarEntryStrategy
Parameters:
out - The RandomAccess to write to. When this method is called, the RandomAccess is positioned at the start of the entry to write. If this method returns successfully, the RandomAccess should be positioned at the next block boundary after the written entry (the Tar file is divided into 512-byte blocks).
is - The stream containing the file's data.
location - The absolute location of the entry in the Tar archive.
effectiveSettings - The effective settings for the entry.
lastModified - The time when the file entity was last modified.

writeDirectory

public void writeDirectory(DataSink out,
                           DirectoryAdapter<?> da,
                           AbsoluteLocation location,
                           TarEntrySettings effectiveSettings,
                           Date lastModified)
Override the inherited implementation to add a Pax header before the ustar header.

Specified by:
writeDirectory in interface TarEntryStrategy
Overrides:
writeDirectory in class V7TarEntryStrategy
Parameters:
out - The DataSink to write to. This may be a RandomAccess object. When this method is called, the DataSink is positioned at the start of the entry to write. If this method returns successfully, the DataSink should be positioned at the next block boundary after the written entry (the Tar file is divided into 512-byte blocks).
da - The directory to add to the Tar file.
location - The absolute location of the entry in the Tar archive.
effectiveSettings - The effective settings for the entry.
lastModified - The time when the directory entity was last modified.