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

public Class TarGenerator

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .File, .FileInputStream, .FileNotFoundException, .IOException, .InputStream, .PipedInputStream, .PipedOutputStream, java.nio.charset.Charset, .StandardCharsets, java.util.ArrayList, .List, org.hsqldb.lib.InputStreamInterface, .InputStreamWrapper, .StringUtil

Generates a tar archive from specified Files and InputStreams. Modified by fredt for hot backup
Author
Blaine Simpson (blaine dot simpson at admc dot com)
Since
2.0.0
Version
2.5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
TarGenerator.TarEntrySupplicant

Slots for supplicant files and input streams to be added to a Tar archive.

Field Summary

Modifier and TypeField and Description
protected TarFileOutputStream
protected List<TarGenerator.TarEntrySupplicant>
protected long

Constructor Summary

AccessConstructor and Description
public
TarGenerator(File
Absolute or relative (from user.dir) File for tar file to be created. getName() Suffix must indicate tar file and may indicate a compression method.
inFile
,
boolean
True to replace an existing file of same path.
overWrite
,
Integer
Null will use default tar value.
blocksPerRecord
)

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

Method Summary

Modifier and TypeMethod and Description
public long
getPaxThreshold()

Returns: long

public void
public void
queueEntry(String entryPath, File file)

public void
public void
queueEntry(String
String
entryPath
,
InputStream
InputStream
inStream
,
int
int
maxBytes
)

This method does not support Pax Interchange Format, nor data sizes greater than 2G.

public void
setPaxThreshold(long
long
paxThreshold
)

When data file is this size or greater, in bytes, a Pix Interchange Format 'x' record will be created and used for the file entry.

public void
write()

This method does release all of the streams, even if there is a failure.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

archiveback to summary
protected TarFileOutputStream archive
entryQueueback to summary
protected List<TarGenerator.TarEntrySupplicant> entryQueue
paxThresholdback to summary
protected long paxThreshold

Constructor Detail

TarGeneratorback to summary
public TarGenerator(File inFile, boolean overWrite, Integer blocksPerRecord) 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) File for tar file to be created. getName() Suffix must indicate tar file and may indicate a compression method.

overWrite:boolean

True to replace an existing file of same path.

blocksPerRecord:Integer

Null will use default tar value.

Exceptions
IOException:
on access failure

Method Detail

getPaxThresholdback to summary
public long getPaxThreshold()
Returns:long

long

See Also
setPaxThreshold(long)
queueEntryback to summary
public void queueEntry(File file) throws FileNotFoundException, TarMalformatException
queueEntryback to summary
public void queueEntry(String entryPath, File file) throws FileNotFoundException, TarMalformatException
queueEntryback to summary
public void queueEntry(String entryPath, InputStreamInterface is) throws FileNotFoundException, TarMalformatException
queueEntryback to summary
public void queueEntry(String entryPath, InputStream inStream, int maxBytes) throws IOException, TarMalformatException

This method does not support Pax Interchange Format, nor data sizes greater than 2G.

This limitation may or may not be eliminated in the future.

Parameters
entryPath:String

String

inStream:InputStream

InputStream

maxBytes:int

int

Exceptions
IOException:
on access failure
TarMalformatException:
if malformed
setPaxThresholdback to summary
public void setPaxThreshold(long paxThreshold)

When data file is this size or greater, in bytes, a Pix Interchange Format 'x' record will be created and used for the file entry.

Limitation At this time, PAX is only implemented for entries added as Files, not entries added as Stream.

Parameters
paxThreshold:long

long

writeback to summary
public void write() throws IOException, TarMalformatException

This method does release all of the streams, even if there is a failure.

Exceptions
IOException:
on access failure
TarMalformatException:
if malformed
org.hsqldb.lib.tar back to summary

protected Class TarGenerator.TarEntrySupplicant

extends Object
Class Inheritance

Slots for supplicant files and input streams to be added to a Tar archive.
Author
Blaine Simpson (blaine dot simpson at admc dot com)

Field Summary

Modifier and TypeField and Description
protected long
public static final String
protected String
pack-priv static final byte[]
protected InputStreamInterface
protected long
protected String
protected boolean
protected final long
protected byte[]
pack-priv static Character
protected TarFileOutputStream
pack-priv static final byte[]

Constructor Summary

AccessConstructor and Description
protected
TarEntrySupplicant(String path, char typeFlag, TarFileOutputStream tarStream, long paxThreshold)

public
TarEntrySupplicant(String
String
path
,
File
File
file
,
TarFileOutputStream
TarFileOutputStream
tarStream
,
long
long
paxThreshold
)

After instantiating a TarEntrySupplicant, the user must either invoke write() or close(), to release system resources on the input File/Stream.

public
TarEntrySupplicant(String path, InputStreamInterface is, TarFileOutputStream tarStream, long paxThreshold)

public
TarEntrySupplicant(String
String
path
,
InputStream
InputStream
origStream
,
int
This method will fail if more than maxBytes bytes are supplied on the specified InputStream. As the type of this parameter enforces, the max size you can request is 2GB.
maxBytes
,
char
char
typeFlag
,
TarFileOutputStream
TarFileOutputStream
tarStream
)

After instantiating a TarEntrySupplicant, the user must either invoke write() or close(), to release system resources on the input File/Stream.

Method Summary

Modifier and TypeMethod and Description
protected static void
clearField(TarHeaderField field, byte[] target)

protected void
public void
public long
protected static String

Returns:

String
getLameMode
(File
File
file
)

This method is so-named because it only sets the owner privileges, not any "group" or "other" privileges.

public String
protected long
public TarGenerator.TarEntrySupplicant

Returns:

TarEntrySupplicant
makeXentry
()

This creates a 'x' entry for a 0/\0 entry.

public static String
prePaddedOctalString(long val, int width)

public void
write()

Writes entire entry to this object's tarStream.

protected static void
writeField(TarHeaderField field, String newValue, byte[] target)

protected static void
writeField(TarHeaderField field, long newValue, byte[] target)

protected void
writeField(TarHeaderField field, String newValue)

protected void
writeField(TarHeaderField field, long newValue)

protected void
writeField(TarHeaderField field, char c)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dataSizeback to summary
protected long dataSize
DEFAULT_FILE_MODESback to summary
public static final String DEFAULT_FILE_MODES
fileModeback to summary
protected String fileMode
HEADER_TEMPLATEback to summary
pack-priv static final byte[] HEADER_TEMPLATE
inputStreamback to summary
protected InputStreamInterface inputStream
modTimeback to summary
protected long modTime
pathback to summary
protected String path
paxSizedback to summary
protected boolean paxSized
paxThresholdback to summary
protected final long paxThreshold
rawHeaderback to summary
protected byte[] rawHeader
swapOutDelimback to summary
pack-priv static Character swapOutDelim
tarStreamback to summary
protected TarFileOutputStream tarStream
ustarBytesback to summary
pack-priv static final byte[] ustarBytes

Constructor Detail

TarEntrySupplicantback to summary
protected TarEntrySupplicant(String path, char typeFlag, TarFileOutputStream tarStream, long paxThreshold) throws TarMalformatException
TarEntrySupplicantback to summary
public TarEntrySupplicant(String path, File file, TarFileOutputStream tarStream, long paxThreshold) throws FileNotFoundException, TarMalformatException

After instantiating a TarEntrySupplicant, the user must either invoke write() or close(), to release system resources on the input File/Stream.

Parameters
path:String

String

file:File

File

tarStream:TarFileOutputStream

TarFileOutputStream

paxThreshold:long

long

Exceptions
FileNotFoundException:
if not found
TarMalformatException:
if malformed
TarEntrySupplicantback to summary
public TarEntrySupplicant(String path, InputStreamInterface is, TarFileOutputStream tarStream, long paxThreshold) throws TarMalformatException
TarEntrySupplicantback to summary
public TarEntrySupplicant(String path, InputStream origStream, int maxBytes, char typeFlag, TarFileOutputStream tarStream) throws IOException, TarMalformatException

After instantiating a TarEntrySupplicant, the user must either invoke write() or close(), to release system resources on the input File/Stream.

Warning

Do not use this method unless the quantity of available RAM is sufficient to accommodate the specified maxBytes all at one time. This constructor loads all input from the specified InputStream into RAM before anything is written to disk.

Parameters
path:String

String

origStream:InputStream

InputStream

maxBytes:int

This method will fail if more than maxBytes bytes are supplied on the specified InputStream. As the type of this parameter enforces, the max size you can request is 2GB.

typeFlag:char

char

tarStream:TarFileOutputStream

TarFileOutputStream

Exceptions
IOException:
on access failure
TarMalformatException:
if malformed

Method Detail

clearFieldback to summary
protected static void clearField(TarHeaderField field, byte[] target)
clearFieldback to summary
protected void clearField(TarHeaderField field)
closeback to summary
public void close() throws IOException
getDataSizeback to summary
public long getDataSize()
getLameModeback to summary
protected static String getLameMode(File file)

This method is so-named because it only sets the owner privileges, not any "group" or "other" privileges.

This is because of Java limitation. Incredibly, with Java 1.6, the API gives you the power to set privileges for "other" (last nibble in file Mode), but no ability to detect the same.

Parameters
file:File

File

Returns:String

String

getPathback to summary
public String getPath()
headerChecksumback to summary
protected long headerChecksum()
makeXentryback to summary
public TarGenerator.TarEntrySupplicant makeXentry() throws IOException, TarMalformatException

This creates a 'x' entry for a 0/\0 entry.

Returns:TarGenerator.TarEntrySupplicant

TarEntrySupplicant

Exceptions
IOException:
on access failure
TarMalformatException:
if malformed
prePaddedOctalStringback to summary
public static String prePaddedOctalString(long val, int width)
writeback to summary
public void write() throws IOException, TarMalformatException

Writes entire entry to this object's tarStream. This method is guaranteed to close the supplicant's input stream.

Exceptions
IOException:
on access failure
TarMalformatException:
if malformed
writeFieldback to summary
protected static void writeField(TarHeaderField field, String newValue, byte[] target) throws TarMalformatException
writeFieldback to summary
protected static void writeField(TarHeaderField field, long newValue, byte[] target) throws TarMalformatException
writeFieldback to summary
protected void writeField(TarHeaderField field, String newValue) throws TarMalformatException
writeFieldback to summary
protected void writeField(TarHeaderField field, long newValue) throws TarMalformatException
writeFieldback to summary
protected void writeField(TarHeaderField field, char c) throws TarMalformatException