打tar包工具TarUtil(1)

本文介绍了一个名为 TarUtile 的 Java 类,该类用于创建和管理 tar 文件。它支持设置输出文件位置、基本目录、压缩方式及处理长文件路径等特性。通过创建文件集和指定权限,用户可以灵活地定制 tar 归档。

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&gt;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);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值