打tar包工具TarUtil(5)

来源:互联网 发布:淘宝导出数据包 编辑:程序博客网 时间:2024/05/21 19:23

finally
        {
            filesets = savedFileSets;
            if (tOut != null)
            {
                try
                {
                    // close up
                    tOut.close();
                }
                catch (IOException e)
                {
                    //LOG.error(e);
                }
            }
        }
    }
   
    /**
     * tar a file
     * @param file the file to tar
     * @param tOut the output stream
     * @param vPath the path name of the file to tar
     * @param tarFileSet the fileset that the file came from.
     * @throws IOException 抛出IO异常
     */
    protected void tarFile(File file, TarOutputStream tOut, String vPath,
            TarFileSet tarFileSet) throws IOException
    {
        FileInputStream fIn = null;
       
        String fullpath = tarFileSet.getFullpath();
        if (fullpath.length() > 0)
        {
            vPath = fullpath;
        }
        else
        {
            // don't add "" to the archive
            if (vPath.length() <= 0)
            {
                return;
            }
           
            if (file.isDirectory() && !vPath.endsWith("/"))
            {
                vPath += "/";
            }
           
            String prefix = tarFileSet.getPrefix();
            // '/' is appended for compatibility with the zip task.
            if (prefix.length() > 0 && !prefix.endsWith("/"))
            {
                prefix = prefix + "/";
            }
            vPath = prefix + vPath;
        }