Top Description Inners Fields Constructors Methods
org.hsqldb.lib.tar

public Class TarReader

extends Object
Class Inheritance
Imports
org.hsqldb.lib.StringUtil, java.io.File, .FileOutputStream, .IOException, .PipedInputStream, .PipedOutputStream, java.text.SimpleDateFormat, java.util.regex.Pattern

Reads a Tar file for reporting or extraction. N.b. this is not a Reader in the java.io.Reader sense, but in the sense of differentiating tar x and tar t from tar c.

Security Note

Due to pitiful lack of support for file security in Java before version 1.6, this class will only explicitly set permissions if it is compiled for Java 1.6. If it was not, and if your tar entries contain private data in files with 0400 or similar, be aware that they will be extracted with privs such that they can be ready by anybody.

Author
Blaine Simpson (blaine dot simpson at admc dot com)

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
TarReader.TarEntryHeader

A Tar entry header constituted from a header block in a tar file.

Field Summary

Modifier and TypeField and Description
protected TarFileInputStream
public static final int
EXTRACT_MODE

EXTRACT_MODE refuses to overwrite existing files.

protected File
public static final int
protected int
public static final int
OVERWRITE_MODE

OVERWRITE_MODE is just EXTRACT_MODE where we will silently overwrite existing files upon extraction.

protected Pattern[]

Constructor Summary

AccessConstructor and Description
public
TarReader(File
Absolute or relative (from user.dir) path to tar file to be read. Suffix may indicate a compression method.
inFile
,
int
Whether to list, extract-without-overwrite, or extract-with-overwrite.
mode
,
String[]
List of regular expressions to match against tar entry names. If null, all entries will be listed or extracted. If non-null, then only entries with names which match will be extracted or listed.
patternStrings
,
Integer
Null will use default tar value.
readBufferBlocks
,
File
Directory that RELATIVE entries will be extracted relative to. Defaults to current directory (user.dir). Only used for extract modes and relative file entries.
inDir
)

Compression is determined directly by the suffix of the file name in the specified path.

Method Summary

Modifier and TypeMethod and Description
protected void
protected PIFData
public void
read()

protected void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

archiveback to summary
protected TarFileInputStream archive
EXTRACT_MODEback to summary
public static final int EXTRACT_MODE

EXTRACT_MODE refuses to overwrite existing files.

extractBaseDirback to summary
protected File extractBaseDir
LIST_MODEback to summary
public static final int LIST_MODE
modeback to summary
protected int mode
OVERWRITE_MODEback to summary
public static final int OVERWRITE_MODE

OVERWRITE_MODE is just EXTRACT_MODE where we will silently overwrite existing files upon extraction.

patternsback to summary
protected Pattern[] patterns

Constructor Detail

TarReaderback to summary
public TarReader(File inFile, int mode, String[] patternStrings, Integer readBufferBlocks, File inDir) throws IOException

Compression is determined directly by the suffix of the file name in the specified path.

Parameters
inFile:File

Absolute or relative (from user.dir) path to tar file to be read. Suffix may indicate a compression method.

mode:int

Whether to list, extract-without-overwrite, or extract-with-overwrite.

patternStrings:String[]

List of regular expressions to match against tar entry names. If null, all entries will be listed or extracted. If non-null, then only entries with names which match will be extracted or listed.

readBufferBlocks:Integer

Null will use default tar value.

inDir:File

Directory that RELATIVE entries will be extracted relative to. Defaults to current directory (user.dir). Only used for extract modes and relative file entries.

Exceptions
IOException:
on access failure
IllegalArgumentException:
if any given pattern is an invalid regular expression. Don't have to worry about this if you call with null 'patterns' param.
See Also
Pattern

Method Detail

extractFileback to summary
protected void extractFile(TarReader.TarEntryHeader header) throws IOException, TarMalformatException
getPifDataback to summary
protected PIFData getPifData(TarReader.TarEntryHeader header) throws IOException, TarMalformatException
readback to summary
public void read() throws IOException, TarMalformatException
skipFileDataback to summary
protected void skipFileData(TarReader.TarEntryHeader header) throws IOException, TarMalformatException
org.hsqldb.lib.tar back to summary

protected Class TarReader.TarEntryHeader

extends Object
Class Inheritance
Annotations
@SuppressWarnings:serial

A Tar entry header constituted from a header block in a tar file.
Author
Blaine Simpson (blaine dot simpson at admc dot com)

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
protected long
protected char
protected int
protected long
protected String
protected String
protected byte[]
protected SimpleDateFormat
protected boolean

Constructor Summary

AccessConstructor and Description
public
TarEntryHeader(byte[]
May be longer than 512 bytes, but the first 512 bytes MUST COMPRISE a raw tar entry header.
rawHeader
)

Method Summary

Modifier and TypeMethod and Description
public File
generateFile()

Returns: a new Absolutized File object generated from this TarEntryHeader.

public long
public char
public int
public long
public String
protected long
public static int
indexOf(byte[]
byte[]
ba
,
byte
byte
val
,
int
int
from
,
int
int
to
)

Returns: index based at 0 == from

public boolean

Returns:

boolean
isUstar
()

Is this any UStar variant

protected char
protected Long

Returns:

Long
readInteger
(TarHeaderField
TarHeaderField
field
)

Integer as in positive whole number, which does not imply Java types of int or Integer.

protected String
readString(TarHeaderField
TarHeaderField
field
)

Returns: null or String with length() > 0.

public void
setDataSize(long
long
dataSize
)

Setter is needed in order to override header size setting for Pax.

public String

Returns:

String
toString
()

Overrides java.lang.Object.toString.

Choosing not to report fields that we don't write (e.g. "gname"), but which would certainly be useful for a general Java tar client implementation.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

dataSizeback to summary
protected long dataSize
entryTypeback to summary
protected char entryType
fileModeback to summary
protected int fileMode
modTimeback to summary
protected long modTime
ownerNameback to summary
protected String ownerName
pathback to summary
protected String path
rawHeaderback to summary
protected byte[] rawHeader
sdfback to summary
protected SimpleDateFormat sdf
ustarback to summary
protected boolean ustar

Constructor Detail

TarEntryHeaderback to summary
public TarEntryHeader(byte[] rawHeader) throws TarMalformatException
Parameters
rawHeader:byte[]

May be longer than 512 bytes, but the first 512 bytes MUST COMPRISE a raw tar entry header.

Exceptions
TarMalformatException:
if malformed

Method Detail

generateFileback to summary
public File generateFile()
Returns:File

a new Absolutized File object generated from this TarEntryHeader.

getDataSizeback to summary
public long getDataSize()
getEntryTypeback to summary
public char getEntryType()
getFileModeback to summary
public int getFileMode()
getModTimeback to summary
public long getModTime()
getPathback to summary
public String getPath()
headerChecksumback to summary
protected long headerChecksum()
indexOfback to summary
public static int indexOf(byte[] ba, byte val, int from, int to)
Parameters
ba:byte[]

byte[]

val:byte

byte

from:int

int

to:int

int

Returns:int

index based at 0 == from

isUstarback to summary
public boolean isUstar() throws TarMalformatException

Is this any UStar variant

Returns:boolean

boolean

readCharback to summary
protected char readChar(TarHeaderField field) throws TarMalformatException
readIntegerback to summary
protected Long readInteger(TarHeaderField field) throws TarMalformatException

Integer as in positive whole number, which does not imply Java types of int or Integer.

Parameters
field:TarHeaderField

TarHeaderField

Returns:Long

Long

Exceptions
TarMalformatException:
if malformed
readStringback to summary
protected String readString(TarHeaderField field) throws TarMalformatException
Parameters
field:TarHeaderField

TarHeaderField

Returns:String

null or String with length() > 0.

setDataSizeback to summary
public void setDataSize(long dataSize)

Setter is needed in order to override header size setting for Pax.

Parameters
dataSize:long

long

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Choosing not to report fields that we don't write (e.g. "gname"), but which would certainly be useful for a general Java tar client implementation.

This design decision is subject to change.

Returns:String

String

org.hsqldb.lib.tar back to summary

protected Class TarReader.TarEntryHeader.MissingField

extends Exception
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final TarHeaderField

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
getMessage()

Overrides java.lang.Throwable.getMessage.

Returns the detail message string of this throwable.

Field Detail

fieldback to summary
private final TarHeaderField field

Constructor Detail

MissingFieldback to summary
public MissingField(TarHeaderField field)

Method Detail

getMessageback to summary
public String getMessage()

Overrides java.lang.Throwable.getMessage.

Doc from java.lang.Throwable.getMessage.

Returns the detail message string of this throwable.