prefixziptask.java

来自「java编写的OCR软件」· Java 代码 · 共 81 行

JAVA
81
字号
package de.spieleck.helper;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.apache.tools.zip.ZipOutputStream;

import org.apache.tools.ant.taskdefs.Zip;

/**
 * Create a Zipfile allow relocation of zipfile contents.
 * That is, we have an extra attribute <globalprefix>
 * which is textually prepended to all names in zipfile. For example
 * you can use
 * <pre>
 *  &lt;taskdef classname="de.spieleck.helper.PrefixZipTask" name="xzip"
 *        classpath="${name}.jar" />
 *  &lt;xzip zipfile="${release.zip}" globalprefix="${zip.prefix}/">
 *    &lt;fileset refid="releaseFileset"/>
 *    &lt;fileset refid="sampleFileset"/>
 *  &lt;/xzip>
 * </pre>
 * with filesets instead of zipfilesets.
 */
public class PrefixZipTask extends Zip {

    /** Allow a global prefix for names within the Zipfile */
    protected String globalPrefix = null;

    /** 
     * Allow a global prefix for names within the Zipfile 
     * @param globalPrefix the String to prefix all names.
     */
    public void setGlobalPrefix(String globalPrefix)
    {
        this.globalPrefix = globalPrefix;
    }

    /**
     * Patch the path for inclusion in zipfile.
     * @param vPath the unpatched path
     * @return the patched path
     */
    protected String zipPath(String vPath)
    {
        return globalPrefix == null ? vPath : globalPrefix + vPath;
    }

    /**
     * Patch zipDir(), insert {@link #globalPrefix} if appropriate.
     * @since patch
     */
    protected void zipDir(File dir, ZipOutputStream zOut, String vPath,
                          int mode)
        throws IOException 
    {
        super.zipDir(dir, zOut, zipPath(vPath), mode);
    }

    /**
     * Patch zipFile(), insert {@link #globalPrefix} if appropriate.
     * @since patch
     */
    protected void zipFile(InputStream in, ZipOutputStream zOut, String vPath,
                           long lastModified, File fromArchive, int mode)
        throws IOException 
    {
        super.zipFile(in, zOut, zipPath(vPath), lastModified,fromArchive,mode);
    }

    /**
     * @since patch
     */
    public void reset() {
        globalPrefix = null;
        super.reset();
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?