當前位置: 首頁>>代碼示例>>Java>>正文


Java ZipEntry類代碼示例

本文整理匯總了Java中org.apache.tools.zip.ZipEntry的典型用法代碼示例。如果您正苦於以下問題:Java ZipEntry類的具體用法?Java ZipEntry怎麽用?Java ZipEntry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ZipEntry類屬於org.apache.tools.zip包,在下文中一共展示了ZipEntry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeTo

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
public void writeTo(OutputStream out) throws IOException {
    final Set<String> filenames = new HashSet<String>();
    final ZipOutputStream zipout = new ZipOutputStream(out);
    for (IFile f : container.getFiles()) {
        assertNoAbsolutePath(f);
        assertNoDuplicates(filenames, f);
        ZipEntry entry = new ZipEntry(f.getLocalPath());
        entry.setTime(f.getLastModified());
        if (f.getPermissions() != IFile.UNDEF_PERMISSIONS) {
            entry.setUnixMode(f.getPermissions());
        }
        zipout.putNextEntry(entry);
        f.writeTo(zipout);
        zipout.closeEntry();
    }
    zipout.finish();
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:18,代碼來源:Files.java

示例2: getZipEntriesByPath

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
/**
 * パス表現で指定したディレクトリのZipEntryのリストを取得する.
 * <p>
 * expressionで指定した正規表現に対応するエントリーを取得する.
 * (前方一致)
 * </p>
 * <h3>例:expressionに"temp/dataA/xyz"を指定した場合</h3>
 * <ul>
 * <li>temp/dataA/xyzディレクトリ及びその下の階層は含まれる.
 * <li>temp/dataA/xyzzzディレクトリ及びその下の階層は含まれる.
 * <li>temp/dataA/xyzがファイルであればそのファイルが唯一含まれる.
 * <li>
 * </ul>
 * @param expression パス表現. nullの場合はすべてを対象とする.
 * @return 取得したList. 該當が1件も無い場合は空のリストを返す.
 */
@SuppressWarnings("rawtypes")
public List<ZipEntry> getZipEntriesByPath(String expression) {
    List<ZipEntry> resultList = new ArrayList<ZipEntry>();

    Enumeration entryEnum = this.zipFile.getEntries();
    while (entryEnum.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entryEnum.nextElement();
        if (null != expression) {
            if (0 > entry.getName().indexOf(expression)) {
                // 取得対象に含まない場合はリストへの追加をスキップする.
                continue;
            }
        }
        // 日本語ファイル名を変換する.
        resultList.add(entry);
    }
    return resultList;
}
 
開發者ID:otsecbsol,項目名稱:linkbinder,代碼行數:35,代碼來源:ZipExtractor.java

示例3: getRootDirectory

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
/**
 * ルートディレクトリ名を取得する.
 * @return ルートディレクトリ名.
 */
public String getRootDirectory() {
    String result = null;
    // 直下のファイルがあればルート無しとする。
    List<ZipEntry> list = getZipEntriesByPath();
    for (ZipEntry entry : list) {
        int pos = entry.getName().indexOf('/');
        if (-1 == pos) {
            result = "";
            break;
        } else {
            String rootName = entry.getName().substring(0, pos);
            if (null == result) {
                result = rootName;
            } else {
                if (!result.equals(rootName)) {
                    // 最上位に異なるディレクトリが見つかったということは親無し
                    result = "";
                    break;
                }
            }
        }
    }
    return result;
}
 
開發者ID:otsecbsol,項目名稱:linkbinder,代碼行數:29,代碼來源:ZipExtractor.java

示例4: isFileConflict

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private boolean isFileConflict(File file) throws IOException{
	ZipFile zip = new ZipFile(file, "GBK");
	ZipEntry entry;
	String name;
	String filename;
	File outFile;
	boolean fileConflict=false;
	Enumeration<ZipEntry> en = zip.getEntries();
	while (en.hasMoreElements()) {
		entry = en.nextElement();
		name = entry.getName();
		if (!entry.isDirectory()) {
			name = entry.getName();
			filename =  name;
			outFile = new File(realPathResolver.get(filename));
			if(outFile.exists()){
				fileConflict=true;
				break;
			}
		}
	}
	zip.close();
	return fileConflict;
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:26,代碼來源:PlugAct.java

示例5: getPlugPerms

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private String getPlugPerms(File file) throws IOException{
	ZipFile zip = new ZipFile(file, "GBK");
	ZipEntry entry;
	String name,filename;
	File propertyFile;
	String plugPerms="";
	Enumeration<ZipEntry> en = zip.getEntries();
	while (en.hasMoreElements()) {
		entry = en.nextElement();
		name = entry.getName();
		if (!entry.isDirectory()) {
			name = entry.getName();
			filename =  name;
			//讀取屬性文件的plug.mark屬性
			if(filename.startsWith(PLUG_FILE_PREFIX)&&filename.endsWith(".properties")){
				propertyFile = new File(realPathResolver.get(filename));
				Properties p=new Properties();
				p.load(new FileInputStream(propertyFile));
				plugPerms=p.getProperty(PLUG_PERMS);
			}
		}
	}
	zip.close();
	return plugPerms;
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:27,代碼來源:PlugAct.java

示例6: createZipOutputStream

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
@Test
@BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0, concurrency = 1)
public void createZipOutputStream() throws Exception {
	final String FILE_NAME = "custom/output/zipOutputStream.zip";
	//
	ZipOutputStream value = IoHelper.createZipOutputStream(FILE_NAME);
	System.out.println(value);
	assertNotNull(value);
	//
	String fileName = "custom/output/test.log";
	byte[] contents = IoHelper.read(fileName);
	ZipEntry zipEntry = new ZipEntry(fileName);
	value.putNextEntry(zipEntry);
	value.write(contents);

	// 須加 close,強製寫入
	IoHelper.close(value);
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:19,代碼來源:IoHelperTest.java

示例7: zip

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
public static void zip(String path, List<File> files) throws IOException {
	ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(   
			new FileOutputStream(path), 1024));   
	for(File f : files) {
		String zipName = f.getName();
		if(!f.getName().contains(".png")) { 
			zipName = f.getName() + ".xml"; 
		}
		ZipEntry ze = new ZipEntry(zipName);
		ze.setTime(f.lastModified());
	    DataInputStream dis = new DataInputStream(new BufferedInputStream(   
	                new FileInputStream(f)));   
        zos.putNextEntry(ze);   
        int c;   
        while ((c = dis.read()) != -1) {   
            zos.write(c);   
        }   
	}
	zos.setEncoding("gbk");    
       zos.closeEntry();   
       zos.close();  
}
 
開發者ID:apicloudcom,項目名稱:APICloud-Studio,代碼行數:23,代碼來源:ZipUtil.java

示例8: getInputStream

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
/**
 * Return an InputStream for reading the contents of this Resource.
 * @return an InputStream object.
 * @throws IOException if the zip file cannot be opened,
 *         or the entry cannot be read.
 */
public InputStream getInputStream() throws IOException {
    if (isReference()) {
        return ((Resource) getCheckedRef()).getInputStream();
    }
    final ZipFile z = new ZipFile(getZipfile(), getEncoding());
    ZipEntry ze = z.getEntry(getName());
    if (ze == null) {
        z.close();
        throw new BuildException("no entry " + getName() + " in "
                                 + getArchive());
    }
    return new FilterInputStream(z.getInputStream(ze)) {
        public void close() throws IOException {
            FileUtils.close(in);
            z.close();
        }
        protected void finalize() throws Throwable {
            try {
                close();
            } finally {
                super.finalize();
            }
        }
    };
}
 
開發者ID:apache,項目名稱:ant,代碼行數:32,代碼來源:ZipResource.java

示例9: getUnixMode

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
/**
 * Determine a Resource's Unix mode or return the given default
 * value if not available.
 */
private int getUnixMode(final Resource r, final ZipFile zf, final int defaultMode) {

    int unixMode = defaultMode;
    if (zf != null) {
        final ZipEntry ze = zf.getEntry(r.getName());
        unixMode = ze.getUnixMode();
        if ((unixMode == 0 || unixMode == UnixStat.DIR_FLAG)
            && !preserve0Permissions) {
            unixMode = defaultMode;
        }
    } else if (r instanceof ArchiveResource) {
        unixMode = ((ArchiveResource) r).getMode();
    }
    return unixMode;
}
 
開發者ID:apache,項目名稱:ant,代碼行數:20,代碼來源:Zip.java

示例10: getSetPermissionsWorksForZipResources

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
@Test
public void getSetPermissionsWorksForZipResources() throws IOException {
    File f = File.createTempFile("ant", ".zip");
    f.deleteOnExit();
    try (ZipOutputStream os = new ZipOutputStream(f)) {
        ZipEntry e = new ZipEntry("foo");
        os.putNextEntry(e);
        os.closeEntry();
    }

    ZipResource r = new ZipResource();
    r.setName("foo");
    r.setArchive(f);
    Set<PosixFilePermission> s =
        EnumSet.of(PosixFilePermission.OWNER_READ,
                   PosixFilePermission.OWNER_WRITE,
                   PosixFilePermission.OWNER_EXECUTE,
                   PosixFilePermission.GROUP_READ);
    PermissionUtils.setPermissions(r, s, null);
    assertEquals(s, PermissionUtils.getPermissions(r, null));
}
 
開發者ID:apache,項目名稱:ant,代碼行數:22,代碼來源:PermissionUtilsTest.java

示例11: zip

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
private void zip(ZipOutputStream out, File f, String base) throws Exception {
    if (f.isDirectory()) {
        File[] fl = f.listFiles();
        out.putNextEntry(new ZipEntry(base + File.separator));
        base = base.length() == 0 ? "" : base + File.separator;
        for (File fl1 : fl) {
            zip(out, fl1, base + fl1.getName());
        }
    } else {
        out.putNextEntry(new ZipEntry(base));
        FileInputStream in = new FileInputStream(f);
        int b;
        while ((b = in.read()) != -1) {
            out.write(b);
        }
        in.close();
    }
}
 
開發者ID:hou80houzhu,項目名稱:rocserver,代碼行數:19,代碼來源:Jile.java

示例12: compress

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
/**
 * 
 * 方法說明:壓縮文件
 * 
 * @param out
 *            輸出流
 * @param f
 *            輸出文件
 * @param base
 *            可無
 * @throws Exception
 */
private static void compress(ZipOutputStream out, File f, String base) throws Exception
{
	if (f.isDirectory()) {
		File[] fl = f.listFiles();
		out.putNextEntry(new ZipEntry(base + "/"));
		base = base.length() == 0 ? "" : base + "/";
		for (int i = 0; i < fl.length; i++) {
			compress(out, fl[i], base + fl[i].getName());
		}
	} else {
		out.putNextEntry(new ZipEntry(base));
		FileInputStream in = new FileInputStream(f);
		int b;
		while ((b = in.read()) != -1) {
			out.write(b);
		}
		in.close();
	}
}
 
開發者ID:winture,項目名稱:wt-studio,代碼行數:32,代碼來源:FileUtil.java

示例13: unzipToDirectory

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
private static void unzipToDirectory(ZipFile zipFile, File destDir) throws IOException {
    byte[] buffer = new byte[4096];
    Enumeration entries = zipFile.getEntries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        if (entry.isDirectory()) {
            File dir = new File(destDir, entry.getName());
            InstallUtils.createDirectory(dir);
        } else {
            File file = new File(destDir, entry.getName());
            InstallUtils.createDirectory(file.getParentFile());
            OutputStream out = null;
            InputStream in = null;
            try {
                out = new BufferedOutputStream(new FileOutputStream(file));
                in = zipFile.getInputStream(entry);
                Unzip.copy(in, out, buffer);
            } finally {
                InstallUtils.close(in);
                InstallUtils.close(out);
            }
            Unzip.setFilePermissions(file, entry);
        }
    }
}
 
開發者ID:WASdev,項目名稱:ci.ant,代碼行數:26,代碼來源:Unzip.java

示例14: handleDir

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
private void handleDir(File dir, ZipOutputStream zipOut) throws IOException {
	FileInputStream fileIn;
	File[] files;

	files = dir.listFiles();

	if (files.length == 0) {// create if empty
		this.zipOut.putNextEntry(new ZipEntry(dir.toString() + "/"));
		this.zipOut.closeEntry();
	} else {// handle directory and file if not empty
		for (File fileName : files) {
			if (fileName.isDirectory()) {
				handleDir(fileName, this.zipOut);
			} else {
				fileIn = new FileInputStream(fileName);
				this.zipOut.putNextEntry(new ZipEntry(fileName.toString()));

				while ((this.readedBytes = fileIn.read(this.buf)) > 0) {
					this.zipOut.write(this.buf, 0, this.readedBytes);
				}

				this.zipOut.closeEntry();
			}
		}
	}
}
 
開發者ID:ezScrum,項目名稱:ezScrum,代碼行數:27,代碼來源:AntZip.java

示例15: putNextEntry

import org.apache.tools.zip.ZipEntry; //導入依賴的package包/類
/**
 * Begins writing a new JAR file entry and positions the stream
 * to the start of the entry data. This method will also close
 * any previous entry. The default compression method will be
 * used if no compression method was specified for the entry.
 * The current time will be used if the entry has no set modification
 * time.
 *
 * @param ze the ZIP/JAR entry to be written
 * @throws java.util.zip.ZipException if a ZIP error has occurred
 * @throws IOException                if an I/O error has occurred
 */
public void putNextEntry(org.apache.tools.zip.ZipEntry ze) throws IOException
{
    if (firstEntry)
    {
        // Make sure that extra field data for first JAR
        // entry includes JAR magic number id.
        byte[] edata = ze.getExtra();
        if (edata != null && !hasMagic(edata))
        {
            // Prepend magic to existing extra data
            byte[] tmp = new byte[edata.length + 4];
            System.arraycopy(tmp, 4, edata, 0, edata.length);
            edata = tmp;
        }
        else
        {
            edata = new byte[4];
        }
        set16(edata, 0, JAR_MAGIC); // extra field id
        set16(edata, 2, 0);         // extra field size
        ze.setExtra(edata);
        firstEntry = false;
    }
    super.putNextEntry(ze);
}
 
開發者ID:OpenNMS,項目名稱:installer,代碼行數:38,代碼來源:JarOutputStream.java


注:本文中的org.apache.tools.zip.ZipEntry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。