org.at4j.tar.builder
Class TarStreamBuilder

java.lang.Object
  extended by org.at4j.archive.builder.AbstractArchiveBuilder<TarStreamBuilder,TarEntrySettings>
      extended by org.at4j.tar.builder.TarStreamBuilder
All Implemented Interfaces:
ArchiveBuilder<TarStreamBuilder,TarEntrySettings>

public class TarStreamBuilder
extends AbstractArchiveBuilder<TarStreamBuilder,TarEntrySettings>

This Tar builder writes its output to a stream. Apart from that, and that data from streams cannot be added to it, it works just like the other TarBuilder.

Since:
1.0
Author:
Karl Gustafsson
See Also:
TarBuilder, TarFile

Constructor Summary
TarStreamBuilder(OutputStream os, TarBuilderSettings settings)
          Create a new Tar archive builder on an already open OutputStream object.
TarStreamBuilder(WritableFile f)
          Create a Tar builder using the default settings.
TarStreamBuilder(WritableFile f, TarBuilderSettings settings)
          Create a Tar builder using the supplied settings.
 
Method Summary
protected  void addDirectoryCallback(AbsoluteLocation location, Object d, TarEntrySettings effectiveSettings, Date lastModified)
          This callback method is implemented by subclasses to add a directory entry to the archive.
protected  void addFileCallback(AbsoluteLocation location, ReadableFile f, TarEntrySettings effectiveSettings, Date lastModified)
          This callback method is implemented by subclasses to add a file entry to the archive.
protected  void assertNotClosed()
          Subclasses implement this method to throw an IllegalStateException if it is called after the archive builder has been closed.
 void close()
          This method finishes writing the Tar file and closes it.
protected  void finalize()
           
protected  TarEntrySettings getDefaultDefaultDirectoryEntrySettings()
          Subclasses implement this method to return a default settings object for directory entries if the client does not specify one when creating the archive builder object.
protected  TarEntrySettings getDefaultDefaultFileEntrySettings()
          Subclasses implement this method to return a default settings object for file entries if the client does not specify one when creating the archive builder object.
 boolean isClosed()
          Is this archive builder closed?
 
Methods inherited from class org.at4j.archive.builder.AbstractArchiveBuilder
add, add, add, add, add, add, add, add, add, addRecursively, addRecursively, addRecursively, addRecursively, addRecursively, addRule, addRules, getDefaultDirectoryEntrySettings, getDefaultFileEntrySettings, getEffectiveSettingsForDirectory, getEffectiveSettingsForDirectory, getEffectiveSettingsForFile, getEffectiveSettingsForFile, getRules, getThis, removeRule, setDefaultDirectoryEntrySettings, setDefaultFileEntrySettings
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TarStreamBuilder

public TarStreamBuilder(WritableFile f)
                 throws WrappedIOException
Create a Tar builder using the default settings. (See TarBuilderSettings.)

Parameters:
f - The file to write the archive to. The previous contents of this file is discarded. If this method completes successfully, the target file is locked for writing until close() is called.
Throws:
WrappedIOException - On I/O errors.
See Also:
TarStreamBuilder(WritableFile, TarBuilderSettings), TarStreamBuilder(OutputStream, TarBuilderSettings)

TarStreamBuilder

public TarStreamBuilder(WritableFile f,
                        TarBuilderSettings settings)
                 throws WrappedIOException
Create a Tar builder using the supplied settings.

Parameters:
f - The file to write the archive to. The previous contents of this file is discarded. If this method completes successfully, the target file is locked for writing until close() is called.
settings - The settings for the builder. Set this to null to use the default settings.
Throws:
WrappedIOException - On I/O errors.
See Also:
TarStreamBuilder(WritableFile), TarStreamBuilder(OutputStream, TarBuilderSettings)

TarStreamBuilder

public TarStreamBuilder(OutputStream os,
                        TarBuilderSettings settings)
                 throws WrappedIOException
Create a new Tar archive builder on an already open OutputStream object. It will use the supplied settings object.

Parameters:
os - The output stream to write data to. This stream is not closed when close() is called. The Tar builder assumes that it has exclusive access to this OutputStream.
settings - The settings for the builder. Set this to null to use the default settings.
Throws:
WrappedIOException - On I/O errors.
See Also:
TarStreamBuilder(WritableFile, TarBuilderSettings)
Method Detail

getDefaultDefaultDirectoryEntrySettings

protected TarEntrySettings getDefaultDefaultDirectoryEntrySettings()
Description copied from class: AbstractArchiveBuilder
Subclasses implement this method to return a default settings object for directory entries if the client does not specify one when creating the archive builder object.

Specified by:
getDefaultDefaultDirectoryEntrySettings in class AbstractArchiveBuilder<TarStreamBuilder,TarEntrySettings>
Returns:
The default settings object for directory entries if none is specified by the client.

getDefaultDefaultFileEntrySettings

protected TarEntrySettings getDefaultDefaultFileEntrySettings()
Description copied from class: AbstractArchiveBuilder
Subclasses implement this method to return a default settings object for file entries if the client does not specify one when creating the archive builder object.

Specified by:
getDefaultDefaultFileEntrySettings in class AbstractArchiveBuilder<TarStreamBuilder,TarEntrySettings>
Returns:
The default settings object for file entries if none is specified by the client.

assertNotClosed

protected void assertNotClosed()
                        throws IllegalStateException
Description copied from class: AbstractArchiveBuilder
Subclasses implement this method to throw an IllegalStateException if it is called after the archive builder has been closed.

Specified by:
assertNotClosed in class AbstractArchiveBuilder<TarStreamBuilder,TarEntrySettings>
Throws:
IllegalStateException - If the archive builder has been closed.

addDirectoryCallback

protected void addDirectoryCallback(AbsoluteLocation location,
                                    Object d,
                                    TarEntrySettings effectiveSettings,
                                    Date lastModified)
                             throws WrappedIOException,
                                    ArchiveEntryAddException
Description copied from class: AbstractArchiveBuilder
This callback method is implemented by subclasses to add a directory entry to the archive. The entry is added at the end of the archive file.

Note: If this method throws an exception, it is the method's responsibility to make sure that the archive file is left in a consistent state. This should probably always mean that the failed entry is truncated from the archive file and that the current archive file pointer is restored to where it was before the method was called.

Specified by:
addDirectoryCallback in class AbstractArchiveBuilder<TarStreamBuilder,TarEntrySettings>
Parameters:
location - The location of the entry in the archive.
d - The directory. This may be a DirectoryView or a File.
effectiveSettings - The effective settings for the entry.
lastModified - The time when the directory was last modified.
Throws:
WrappedIOException - On I/O errors.
ArchiveEntryAddException - If the entry could not be added to the archive for some other reason than an I/O error.

addFileCallback

protected void addFileCallback(AbsoluteLocation location,
                               ReadableFile f,
                               TarEntrySettings effectiveSettings,
                               Date lastModified)
                        throws WrappedIOException,
                               ArchiveEntryAddException
Description copied from class: AbstractArchiveBuilder
This callback method is implemented by subclasses to add a file entry to the archive. The entry is added at the end of the archive file.

Note: If this method throws an exception, it is the method's responsibility to make sure that the archive file is left in a consistent state. This should probably always mean that the failed entry is truncated from the archive file and that the current archive file pointer is restored to where it was before the method was called.

Specified by:
addFileCallback in class AbstractArchiveBuilder<TarStreamBuilder,TarEntrySettings>
Parameters:
location - The location of the entry in the archive.
f - The file.
effectiveSettings - The effective settings for the entry.
lastModified - The time when the file was last modified.
Throws:
WrappedIOException - On I/O errors.
ArchiveEntryAddException - If the entry could not be added to the archive for some other reason than an I/O error.

isClosed

public boolean isClosed()
Description copied from interface: ArchiveBuilder
Is this archive builder closed?

Returns:
true if this archive builder is closed.

close

public void close()
           throws WrappedIOException
This method finishes writing the Tar file and closes it. It also releases the write lock on the created Tar file, if it is in a locking FileSystem.

Throws:
WrappedIOException - On I/O errors.

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable