public class TarUtil extends MatchingTask
{
private static final int MODE = 8;
private File tarFileObj;
private File baseDir;
private TarLongFileMode longFileMode = new TarLongFileMode();
private List<TarFileSet> filesets = new ArrayList<TarFileSet>();
/**
* Indicates whether the user has been warned about long files already.
*/
private boolean longWarningGiven = false;
private TarCompressionMethod compression = new TarCompressionMethod();
/**
* Add a new fileset with the option to specify permissions
* @return the tar fileset to be used as the nested element.
*/
public TarFileSet createTarFileSet()
{
TarFileSet fileset = new TarFileSet();
filesets.add(fileset);
return fileset;
}
/**
* Set is the name/location of where to create the tar file.
* @since Ant 1.5
* @param destFile The output of the tar
*/
public void setDestFile(File destFile)
{
this.tarFileObj = destFile;
}
/**
* This is the base directory to look in for things to tar.
* @param baseDirectory the base directory.
*/
public void setBasedir(File baseDirectory)
{
this.baseDir = baseDirectory;
}
/**
* Set how to handle long files, those with a path>100 chars.
* Optional, default=warn.
*
* Allowable values are
* <ul>
* <li> truncate - paths are truncated to the maximum length
* <li> fail - paths greater than the maximum cause a build exception
* <li> warn - paths greater than the maximum cause a warning and GNU is used
* <li> gnu - GNU extensions are used for any paths greater than the maximum.
* <li> omit - paths greater than the maximum are omitted from the archive
* </ul>
* @param mode the mode string to handle long files.
* @deprecated setLongFile(String) is deprecated and is replaced with
* setLongFile(Tar.TarLongFileMode) to make Ant's Introspection
* mechanism do the work and also to encapsulate operations on
* the mode in its own class.
*/
public void setLongfile(String mode)
{
log("DEPRECATED - The setLongfile(String) method has been deprecated."
+ " Use setLongfile(Tar.TarLongFileMode) instead.");
this.longFileMode = new TarLongFileMode();
longFileMode.setValue(mode);
}
本文介绍了一个名为 TarUtile 的 Java 类,该类用于创建和管理 tar 文件。它支持设置输出文件位置、基本目录、压缩方式及处理长文件路径等特性。通过创建文件集和指定权限,用户可以灵活地定制 tar 归档。
301

被折叠的 条评论
为什么被折叠?



