public class TarFile extends Object implements Archive<TarEntry,TarDirectoryEntry>
TarFile
is an Archive
containing TarEntry
:s loaded
from a file. Tar entries may be files, directories or symbolic links. They
contain metadata about the file system entity that was used to create the tar
entry such as its time of last modification and its owner user and group
id:s.
The Tar file format is fairly simple, but it has evolved through a few versions since it was first defined. The following formats are supported by this object:
TarEntry
objects.UstarEntry
objects.UstarEntry
objects.PaxEntry
objects.
The entries in a Tar archive are positioned in a directory hierarchy. Parent
directories of entries may be absent. In that case they are represented by
TarDirectoryEntry
objects using default directory settings.
If the file used to create this object is in a locking
FileSystem
, it is locked for reading by this object
until it is close()
:d.
A TarFile
object should be safe to use concurrently from several
parallel threads without any external synchronization.
Note on character encodings: By default, metadata about Tar entries is encoded using the default character encoding of the platform where the tar file is created. This makes it necessary for those reading Tar files to know which character encoding that was used when the archive was created. This is often, but not always, Codepage 437 on Windows or UTF-8 on Unix. The only exception to this rule is the Pax variables that are always encoded using UTF-8. If Tar entries in a Pax compatible archive contains non-ASCII characters, the Tar entry path is (often) stored in the Pax header, making the archive portable between different platforms.
The Tar file format is described well in the Gnu Tar manual.
This object has a main method that, when run, prints out the contents of a Tar file passed to it as an argument.
TarExtractor
Constructor and Description |
---|
TarFile(org.entityfs.RandomlyAccessibleFile f)
Create a new Tar file archive object that reads data from the supplied
file.
|
TarFile(org.entityfs.RandomlyAccessibleFile f,
Charset entryNameCharset)
Create a new Tar file archive object that reads data from the supplied
file.
|
Modifier and Type | Method and Description |
---|---|
protected void |
assertNotClosed()
This method throws an
IllegalStateException if this object has
been closed. |
void |
clear() |
void |
close()
Close this Tar file.
|
boolean |
containsKey(Object key)
Does the Tar archive contain the specified key (which should be an
AbsoluteLocation object)? |
boolean |
containsValue(Object value)
Does the Tar archive contain the specified value (which should be some
kind of
TarEntry object)? |
Set<Map.Entry<org.entityfs.el.AbsoluteLocation,TarEntry>> |
entrySet()
Get a read only set containing the entries in the Tar archive.
|
protected void |
finalize() |
TarEntry |
get(Object key)
Get the
TarEntry stored at the specified absolute location in the
Tar file. |
org.entityfs.RandomlyAccessibleFile |
getBackingFile()
Get the file that this object was created from.
|
TarDirectoryEntry |
getRootEntry()
Get the root directory entry for the Tar file.
|
boolean |
isEmpty()
This method always returns
false since a Tar archive always has
its root directory entry. |
Set<org.entityfs.el.AbsoluteLocation> |
keySet()
Get a read only set containing all the
AbsoluteLocation :s where
Tar entries are stored in the Tar file. |
static void |
main(String[] args) |
TarEntry |
put(org.entityfs.el.AbsoluteLocation key,
TarEntry value) |
void |
putAll(Map<? extends org.entityfs.el.AbsoluteLocation,? extends TarEntry> m) |
TarEntry |
remove(Object key) |
int |
size()
Get the number of Tar entries in the archive.
|
Collection<TarEntry> |
values()
Get a read only collection containing all
TarEntry objects in the
Tar file. |
public TarFile(org.entityfs.RandomlyAccessibleFile f)
If the file is in a locking FileSystem
, it is locked
for reading by this method. The read lock is released when this object is
close()
:d. If this method returns with an error, the file is not
locked.
f
- The Tar file.TarFile(RandomlyAccessibleFile, Charset)
public TarFile(org.entityfs.RandomlyAccessibleFile f, Charset entryNameCharset)
If the file is in a locking FileSystem
, it is locked
for reading by this method. The read lock is released when this object is
close()
:d. If this method returns with an error, the file is not
locked.
f
- The Tar file.entryNameCharset
- The charset to use for interpreting text metadata
in the Tar file.TarFile(RandomlyAccessibleFile)
protected void assertNotClosed() throws IllegalStateException
IllegalStateException
if this object has
been closed.IllegalStateException
- If this object has been closed.public TarDirectoryEntry getRootEntry()
/
in the Tar file.
This entry is never present in the Tar file itself, so the returned
object is always a TarDirectoryEntry
(and not some subclass of
that object).
getRootEntry
in interface Archive<TarEntry,TarDirectoryEntry>
public void clear() throws UnsupportedOperationException
clear
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
UnsupportedOperationException
- Always.public boolean containsKey(Object key) throws IllegalStateException
AbsoluteLocation
object)?containsKey
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
key
- The key to search for.true
if the supplied key is present in the Tar file.IllegalStateException
- If the Tar file has been closed.public boolean containsValue(Object value) throws IllegalStateException
TarEntry
object)?containsValue
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
value
- The value to search for.true
if the Tar file contains the specified value.IllegalStateException
- If the Tar file has been closed.public Set<Map.Entry<org.entityfs.el.AbsoluteLocation,TarEntry>> entrySet() throws IllegalStateException
entrySet
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
IllegalStateException
- If the Tar archive has been closed.public TarEntry get(Object key) throws IllegalStateException
TarEntry
stored at the specified absolute location in the
Tar file.get
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
key
- The AbsoluteLocation
where the Tar entry is stored.null
if no Tar entry is stored at the
specified location.IllegalStateException
- If the Tar archive has been closed.public boolean isEmpty() throws IllegalStateException
false
since a Tar archive always has
its root directory entry.isEmpty
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
false
, always.IllegalStateException
- If the Tar archive has been closed.public Set<org.entityfs.el.AbsoluteLocation> keySet() throws IllegalStateException
AbsoluteLocation
:s where
Tar entries are stored in the Tar file.keySet
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
IllegalStateException
- If the Tar archive has been closed.public TarEntry put(org.entityfs.el.AbsoluteLocation key, TarEntry value) throws UnsupportedOperationException
put
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
UnsupportedOperationException
- Always.public void putAll(Map<? extends org.entityfs.el.AbsoluteLocation,? extends TarEntry> m) throws UnsupportedOperationException
putAll
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
UnsupportedOperationException
- Always.public TarEntry remove(Object key) throws UnsupportedOperationException
remove
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
UnsupportedOperationException
- Always.public int size() throws IllegalStateException
size
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
IllegalStateException
- If the Tar archive has been closed.public Collection<TarEntry> values() throws IllegalStateException
TarEntry
objects in the
Tar file.values
in interface Map<org.entityfs.el.AbsoluteLocation,TarEntry>
IllegalStateException
- If the Tar archive has been closed.public org.entityfs.RandomlyAccessibleFile getBackingFile()
public void close()
This method can safely be called several times.
close
in interface Archive<TarEntry,TarDirectoryEntry>
protected void finalize() throws Throwable
public static void main(String[] args)