CkTar Java Reference Documentation

CkTar

API for creating and extracting TAR archives. Also supports creating and extracting .tar.gz (.tgz), .tar.bz2, and .tar.Z (compressed TAR archives, also known as compressed tarball archives). Can read/write the following TAR formats: (1) GNU tar 1.13.x format, (2) PAX -- POSIX 1003.1-2001 format, (3) USTAR -- POSIX 1003.1-1988 format.

Object Creation

CkTar obj = new CkTar();

Properties

boolean get_CaptureXmlListing();
void put_CaptureXmlListing(boolean newVal);

Introduced in version 9.5.0.46

If true, then untar methods, such as Untar, UntarGz, UntarBz2, and UntarZ, will also capture an XML listing of the contents in the XmlListing property. The format of the XML contained in XmlListing is identical to what is returned by the ListXml method. The default value is false.

void get_Charset(CkString str);
String charset();
void put_Charset(String newVal);

Character encoding to be used when interpreting filenames within .tar archives for untar operations. The default is "utf-8", and this is typically not changed. (The WriteTar methods always uses utf-8 to store filenames within the TAR archive.)

void get_DebugLogFilePath(CkString str);
String debugLogFilePath();
void put_DebugLogFilePath(String newVal);

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

int get_DirMode();
void put_DirMode(int newVal);

The directory permissions to used in WriteTar* methods. The default is octal 0755. This is the value to be stored in the "mode" field of each TAR header for a directory entries.

void get_DirPrefix(CkString str);
String dirPrefix();
void put_DirPrefix(String newVal);

A prefix to be added to each file's path within the TAR archive as it is being created. For example, if this property is set to the string "subdir1", then "subdir1/" will be prepended to each file's path within the TAR.

Note: This property does not apply to files added using the AddFile2 method, which directly specifies the path-in-tar.

int get_FileMode();
void put_FileMode(int newVal);

The file permissions to used in WriteTar* methods. The default is octal 0644. This is the value to be stored in the "mode" field of each TAR header for a file entries.

int get_GroupId();
void put_GroupId(int newVal);

The default numerical GID to be stored in each TAR header when writing TAR archives. The default value is 1000.

void get_GroupName(CkString str);
String groupName();
void put_GroupName(String newVal);

The default group name to be stored in each TAR header when writing TAR archives. The default value is the logged-on username of the application's process.

int get_HeartbeatMs();
void put_HeartbeatMs(int newVal);

This is the number of milliseconds between each AbortCheck event callback. The AbortCheck callback allows an application to abort any TAR operation prior to completion. If HeartbeatMs is 0, no AbortCheck event callbacks will occur.

void get_LastErrorHtml(CkString str);
String lastErrorHtml();

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

void get_LastErrorText(CkString str);
String lastErrorText();

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

Concept of LastErrorText

LastErrorText Standard Information

void get_LastErrorXml(CkString str);
String lastErrorXml();

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

boolean get_LastMethodSuccess();
void put_LastMethodSuccess(boolean newVal);

Introduced in version 9.5.0.52

Indicate whether the last method call succeeded or failed. A value of true indicates success, a value of false indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = true and failure = false.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to true. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

boolean get_MatchCaseSensitive();
void put_MatchCaseSensitive(boolean newVal);

Introduced in version 9.5.0.46

Determines whether pattern matching for the MustMatch and MustNotMatch properties is case-sensitive or not. The default value is false.

void get_MustMatch(CkString str);
String mustMatch();
void put_MustMatch(String newVal);

Introduced in version 9.5.0.46

If set, then file paths must match this pattern when creating TAR archives, or when extracting from TAR archives. If a file does not match, it will not be included when creating a TAR, or it will not be extracted when extracting from a TAR. This property also applies to methods that create or extract from compressed TAR archives.

The must-match pattern may include 0 or more asterisk characters, each of which represents 0 or more of any character. For example, the pattern "*.txt" causes only .txt files to be included or extracted. The default value is an empty string, indicating that all files are implicitly matched.

void get_MustNotMatch(CkString str);
String mustNotMatch();
void put_MustNotMatch(String newVal);

Introduced in version 9.5.0.46

If set, then file paths must NOT match this pattern when creating TAR archives, or when extracting from TAR archives. If a file path matches, it will not be included when creating a TAR, or it will not be extracted when extracting from a TAR. This property also applies to methods that create or extract from compressed TAR archives.

The must-not-match pattern may include 0 or more asterisk characters, each of which represents 0 or more of any character. For example, the pattern "*.obj" causes all .obj files to be skipped. The default value is an empty string, indicating that no files are skipped.

boolean get_NoAbsolutePaths();
void put_NoAbsolutePaths(boolean newVal);

If true, then absolute paths are converted to relative paths by removing the leading "/" or "\" character when untarring. This protects your system from unknowingly untarring files into important system directories, such as C:\Windows\system32. The default value is true.

int get_NumDirRoots();

The total number of directory roots set by calling AddDirRoot (i.e. the number of times AddDirRoot was called by the application). A TAR archive is created by calling AddDirRoot for one or more directory tree roots, followed by a single call to WriteTar (or WriteTarBz2, WriteTarGz, WriteTarZ). This allows for TAR archives containing multiple directory trees to be created.

int get_PercentDoneScale();
void put_PercentDoneScale(int newVal);

Introduced in version 9.5.0.49

This property is only valid in programming environment and languages that allow for event callbacks.

Sets the value to be defined as 100% complete for the purpose of PercentDone event callbacks. The defaut value of 100 means that at most 100 event PercentDone callbacks will occur in a method that (1) is event enabled and (2) is such that it is possible to measure progress as a percentage completed. This property may be set to larger numbers to get more fine-grained PercentDone callbacks. For example, setting this property equal to 1000 will provide callbacks with .1 percent granularity. For example, a value of 453 would indicate 45.3% competed. This property is clamped to a minimum value of 10, and a maximum value of 100000.

int get_ScriptFileMode();
void put_ScriptFileMode(int newVal);

The file permissions to used in WriteTar* methods for shell script files (.sh, .csh, .bash, .bsh). The default is octal 0755. This is the value to be stored in the "mode" field of each TAR header for a file entries.

boolean get_SuppressOutput();
void put_SuppressOutput(boolean newVal);

Introduced in version 9.5.0.46

If true, then untar methods, such as Untar, UntarGz, UntarBz2, and UntarZ, do not produce any output. Setting this value equal to true is useful when the CaptureXmlListing is also set to true, which enables an application to get the contents of a TAR archive without extracting. The default value is false.

boolean get_UntarCaseSensitive();
void put_UntarCaseSensitive(boolean newVal);

This property is deprecated. Applications should instead use the MatchCaseSensitive property. Until this property is officially removed, it will behave the same as the MatchCaseSensitive property.

boolean get_UntarDebugLog();
void put_UntarDebugLog(boolean newVal);

Similar to the VerboseLogging property. If set to true, then information about each file/directory extracted in an untar method call is logged to LastErrorText (or LastErrorXml / LastErrorHtml). The default value is false.

boolean get_UntarDiscardPaths();
void put_UntarDiscardPaths(boolean newVal);

If true, then discard all path information when untarring. This causes all files to be untarred into a single directory. The default value is false.

void get_UntarFromDir(CkString str);
String untarFromDir();
void put_UntarFromDir(String newVal);

The directory path where files are extracted when untarring. The default value is ".", meaning that the current working directory of the calling process is used. If UntarDiscardPaths is set, then all files are untarred into this directory. Otherwise, the untar operation will re-create a directory tree rooted in this directory.

void get_UntarMatchPattern(CkString str);
String untarMatchPattern();
void put_UntarMatchPattern(String newVal);

This property is deprecated. It will be removed in a future version.

This property is deprecated. The MustMatch property should be used instead. Until this property is officially removed from the API, it is identical in behavior the MustMatch property.

int get_UntarMaxCount();
void put_UntarMaxCount(int newVal);

Limits the number of files extracted during an untar to this count. The default value is 0 to indicate no maximum. To untar a single file, one might set the UntarMatchPattern such that it will match only the file to be extracted, and also set UntarMaxCount equal to 1. This causes an untar to scan the TAR archive until it finds the matching file, extract it, and then return.

int get_UserId();
void put_UserId(int newVal);

The default numerical UID to be stored in each TAR header when writing TAR archives. The default value is 1000.

void get_UserName(CkString str);
String userName();
void put_UserName(String newVal);

The default user name to be stored in each TAR header when writing TAR archives. The default value is the logged-on username of the application's process.

boolean get_VerboseLogging();
void put_VerboseLogging(boolean newVal);

If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

void get_Version(CkString str);
String version();

Version of the component/library, such as "9.5.0.63"

void get_WriteFormat(CkString str);
String writeFormat();
void put_WriteFormat(String newVal);

The TAR format to use when writing a TAR archive. Valid values are "gnu", "pax", and "ustar". The default value is "gnu".

void get_XmlListing(CkString str);
String xmlListing();
void put_XmlListing(String newVal);

Introduced in version 9.5.0.46

Contains the XML listing of the contents of the TAR archive for the last untar method call (such as Untar, UntarGz, etc.) where the CaptureXmlListing property was set to true.

Methods

boolean AddDirRoot(String dirPath);

Adds a directory tree to be included in the next call to one of the WriteTar* methods. To include multiple directory trees in a .tar, call AddDirRoot multiple times followed by a single call to WriteTar.

Returns true for success, false for failure.

boolean AddDirRoot2(String rootPrefix, String rootPath);

Introduced in version 9.5.0.56

Adds a directory tree to be included in the next call to one of the WriteTar* methods. To include multiple directory trees in a .tar, call AddDirRoot2 (and/or AddDirRoot) multiple times followed by a single call to WriteTar.

The rootPrefix adds a prefix to the path in the TAR for all files added under this root. The rootPrefix should not end with a forward-slash char. For example: This is good: "abc/123", but this is not good: "abc/123/". If the DirPrefix property is also set, its prefix will added first.

Returns true for success, false for failure.

Adding Path Information with Individual Dir Roots

boolean AddFile(String path);

Introduced in version 9.5.0.46

Adds a local file to be included in the next call to one of the WriteTar* methods. To include multiple files or directory trees in a .tar, call AddFile/AddDirRoot multiple times followed by a single call to WriteTar (or WriteTarGz, or WriteTarBz2).

Returns true for success, false for failure.

boolean AddFile2(String filePath, String pathWithinTar);

Introduced in version 9.5.0.69

Adds a local file to be included in the next call to one of the WriteTar* methods. Allows for the path within the TAR to be specified. To include multiple files or directory trees in a .tar, call AddFile/AddFile2/AddDirRoot multiple times followed by a single call to WriteTar (or WriteTarGz, or WriteTarBz2).

Note: The DirPrefix property does not apply to files added via this method because this method explicilty specifies the path-in-tar.

Returns true for success, false for failure.

boolean CreateDeb(String controlPath, String dataPath, String debPath);

Introduced in version 9.5.0.66

Creates a .deb Debian binary package archive from a control.tar.gz and data.tar.gz. The controlPath is the path to the control.tar.gz file (or equivalent), and the dataPath is the path to the data.tar.gz file. The output file path (.deb) is specified in debPath.

Returns true for success, false for failure.

boolean GetDirRoot(int index, CkString outStr);
String getDirRoot(int index);

Returns the value of the Nth directory root. For example, if an application calls AddDirRoot twice, then the NumDirRoots property would have a value of 2, and GetDirRoot(0) would return the path passed to AddDirRoot in the 1st call, and GetDirRoot(1) would return the directory path in the 2nd call to AddDirRoot.

Returns true for success, false for failure.

boolean ListXml(String tarPath, CkString outStr);
String listXml(String tarPath);

Scans a TAR archive and returns XML detailing the files and directories found within the TAR.

Returns true for success, false for failure.

CkTask ListXmlAsync(String tarPath);

Creates an asynchronous task to call the ListXml method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

(Android™) How to Run an Asynchronous Task

(Java) How to Run an Asynchronous Task

boolean SaveLastError(String path);

Saves the last-error information (the contents of LastErrorXml) to an XML formatted file.

Returns true for success, false for failure.

boolean UnlockComponent(String unlockCode);

Unlocks the component allowing for the full functionality to be used. If this method unexpectedly returns false, examine the contents of the LastErrorText property to determine the reason for failure.

Diagnosing UnlockComponent Problems

UnlockComponent LastErrorText shows exact string passed to it.

Verify UnlockComponent Success w/ Purchased Unlock Code

LastErrorText Standard Information

int Untar(String tarPath);

Extracts the files and directories from a TAR archive, reconstructing the directory tree(s) in the local filesystem. The files are extracted to the directory specified by the UntarFromDir property. Returns the number of files and directories extracted, or -1 for failure.

(Android™) Untar a .tar Archive

(Java) Untar a .tar Archive

CkTask UntarAsync(String tarPath);

Creates an asynchronous task to call the Untar method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

(Android™) How to Run an Asynchronous Task

(Java) How to Run an Asynchronous Task

boolean UntarBz2(String tarPath);

Extracts the files and directories from a tar.bz2 (or tar.bzip2) archive, reconstructing the directory tree(s) in the local filesystem. The files are extracted to the directory specified by the UntarFromDir property.

Returns true for success, false for failure.

(Android™) Untar a .tar.bz2 Compressed Archive

(Java) Untar a .tar.bz2 Compressed Archive

CkTask UntarBz2Async(String tarPath);

Creates an asynchronous task to call the UntarBz2 method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

(Android™) How to Run an Asynchronous Task

(Java) How to Run an Asynchronous Task

boolean UntarFirstMatchingToMemory(CkByteData tarFileBytes, String matchPattern, CkByteData outData);

Memory-to-memory untar. The first file matching a pattern in the MustMatch property is extracted and returned.

Returns true for success, false for failure.

int UntarFromMemory(CkByteData tarFileBytes);

Extracts the files and directories from an in-memory TAR archive, reconstructing the directory tree(s) in the local filesystem. The files are extracted to the directory specified by the UntarFromDir property. Returns the number of files and directories extracted, or -1 for failure.

CkTask UntarFromMemoryAsync(CkByteData tarFileBytes);

Creates an asynchronous task to call the UntarFromMemory method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

(Android™) How to Run an Asynchronous Task

(Java) How to Run an Asynchronous Task

boolean UntarGz(String tarPath);

Extracts the files and directories from a tar.gz (or tar.gzip) archive, reconstructing the directory tree(s) in the local filesystem. The files are extracted to the directory specified by the UntarFromDir property.

Returns true for success, false for failure.

(Android™) Untar a .tar.gz (.tgz) Compressed Archive

(Java) Untar a .tar.gz (.tgz) Compressed Archive

CkTask UntarGzAsync(String tarPath);

Creates an asynchronous task to call the UntarGz method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

(Android™) How to Run an Asynchronous Task

(Java) How to Run an Asynchronous Task

boolean UntarZ(String tarPath);

Extracts the files and directories from a tar.Z archive, reconstructing the directory tree(s) in the local filesystem. The files are extracted to the directory specified by the UntarFromDir property.

Returns true for success, false for failure.

(Android™) Untar a .tar.Z (.taz) Compressed Archive

(Java) Untar a .tar.Z (.taz) Compressed Archive

CkTask UntarZAsync(String tarPath);

Creates an asynchronous task to call the UntarZ method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

(Android™) How to Run an Asynchronous Task

(Java) How to Run an Asynchronous Task

boolean VerifyTar(String tarPath);

Verifies that a TAR archive is valid. This method opens the TAR archive and scans the entire file by walking the TAR headers. Returns true if no errors were found. Otherwise returns false.

CkTask VerifyTarAsync(String tarPath);

Creates an asynchronous task to call the VerifyTar method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

(Android™) How to Run an Asynchronous Task

(Java) How to Run an Asynchronous Task

boolean WriteTar(String tarPath);

Writes a TAR archive. The directory trees previously added by calling AddDirRoot one or more times are included in the output TAR archive.

Returns true for success, false for failure.

(Android™) Create TAR Archive

(Java) Create TAR Archive

CkTask WriteTarAsync(String tarPath);

Creates an asynchronous task to call the WriteTar method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

(Android™) How to Run an Asynchronous Task

(Java) How to Run an Asynchronous Task

boolean WriteTarBz2(String bz2Path);

Writes a .tar.bz2 compressed TAR archive. The directory trees previously added by calling AddDirRoot one or more times are included in the output file.

Returns true for success, false for failure.

(Android™) Create TAR BZ2 Compressed Archive (.tar.bz2, .tbz, .tbz2, .tb2)

(Java) Create TAR BZ2 Compressed Archive (.tar.bz2, .tbz, .tbz2, .tb2)

CkTask WriteTarBz2Async(String bz2Path);

Creates an asynchronous task to call the WriteTarBz2 method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

(Android™) How to Run an Asynchronous Task

(Java) How to Run an Asynchronous Task

boolean WriteTarGz(String gzPath);

Writes a .tar.gz (also known as .tgz) compressed TAR archive. The directory trees previously added by calling AddDirRoot one or more times are included in the output file.

Returns true for success, false for failure.

(Android™) Create Compressed .tgz (.tar.gz) TAR Archive

(Java) Create Compressed .tgz (.tar.gz) TAR Archive

CkTask WriteTarGzAsync(String gzPath);

Creates an asynchronous task to call the WriteTarGz method with the arguments provided. (Async methods are available starting in Chilkat v9.5.0.52.)

Note: Async method event callbacks happen in the background thread. Accessing and updating UI elements existing in the main thread may require special considerations.

Returns nil on failure

(Android™) How to Run an Asynchronous Task

(Java) How to Run an Asynchronous Task

Events

Chilkat supports event callbacks in Java (including Android) starting in version 9.5.0.52. To implement an event callback, your application would define and implement a class that derives from CkTarProgress. Your application can implement methods to override some or all of the default/empty method implementations of the CkTarProgress base class.

For example:

// Install an event callback handler to get progress events.
MyTarProgress tarProgress = new MyTarProgress();
http.put_EventCallbackObject(tarProgress);

MyTarProgress example:

import com.chilkatsoft.CkHttpProgress;
import com.chilkatsoft.CkTask;

public class MyTarProgress extends CkTarProgress 
{	
  public boolean AbortCheck()
  {
    System.out.println("AbortCheck");
    // Return true to abort, false to allow the method to continue.
    return false;
  }
  	
  // pctDone is a value from 0 to 100
  // (it is actually value from 0 to the PercentDoneScale property setting)
  public boolean PercentDone(int pctDone)
  {
    System.out.println(pctDone);
    // Return true to abort, false to allow the method to continue.
    // Note: A PercentDone event is the equivalent of an AbortCheck.  
    // When PercentDone events are frequently firing, AbortCheck events are suppressed.
    // AbortCheck events will fire when the time between PercentDone events is longer 
    // than the HeartbeatMs property setting.
    return false;
  }
  
  public void ProgressInfo(String name, String value)
  {
    System.out.println(name + ": " + value);
  }
  
  public void TaskCompleted(CkTask task)
  {
     System.out.println("task completed!");
  }
  
  public boolean NextTarFile(String path, long fileSize, boolean bIsDirectory) 
  {
	  // Return true to skip adding/writing the given file to the TAR archive, return false to NOT skip.
	  return false;
  }
  


}

public boolean AbortCheck();

Provides the opportunity for a method call to be aborted. The AbortCheck event is fired periodically based on the value of the HeartbeatMs property. If HeartbeatMs is 0, then no AbortCheck events will fire. As an example, to fire 5 AbortCheck events per second, set the HeartbeatMs property equal to 200. Return true to abort; return false to continue (not abort)

public boolean NextTarFile(String path, long long fileSize, boolean isDirectory);

Called for methods that create a TAR archive. This event is called just before a file is to be added to the TAR. Return true to skip adding the file. Return false to allow the file to be added.

public boolean PercentDone(int pctDone);

Provides the percentage completed for any method that involves network communications or time-consuming processing (assuming it is a method where a percentage completion can be measured). This event is only fired when it is possible to know a percentage completion, and when it makes sense to express the operation as a percentage completed. The pctDone argument will have a value from 1 to 100. For operations (Chilkat method calls) that complete very quickly, the number of PercentDone callbacks will vary, but the final callback should have a value of 100. For long running operations, no more than one callback per percentage point will occur (for example: 1, 2, 3, ... 98, 99, 100).

The PercentDone callback counts as an AbortCheck event. For method calls that complete quickly such that PercentDone events fire, it may be that AbortCheck events don't fire because the opportunity to abort is already provided in the PercentDone callback. For time consuming operations, where the amount of time between PercentDone callbacks are long, AbortCheck callbacks may be used to allow for the operation to be aborted in a more responsive manner.

Return true to abort; return false to continue (not abort)

public void ProgressInfo(String name, String value);

A general name/value event that provides information about what is happening during a method call. To find out what information is available, write code to handle this event and log the name/value pairs. Most are self-explanatory.

public void TaskCompleted(CkTask task);

Called in the background thread when an asynchronous task completes.

public void TextData(String data);

Text data provided by certain methods.