⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entrytrackingjaroutputstream.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/**
 * Copyright (c) 2004 Craig Setera
 * All Rights Reserved.
 * Licensed under the Eclipse Public License - v 1.0
 * For more information see http://www.eclipse.org/legal/epl-v10.html
 */
package eclipseme.core.internal.utils;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;

/**
 * JarOutputStream subclass capable of tracking and checking
 * existence of entries that have been made.
 * <p />
 * Copyright (c) 2004 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision: 1.2 $
 * <br>
 * $Date: 2004/11/22 02:11:38 $
 * <br>
 * @author Craig Setera
 */

public class EntryTrackingJarOutputStream extends JarOutputStream {

	/**
	 * 
	 * @uml.property name="addedEntryNames"
	 * @uml.associationEnd 
	 * @uml.property name="addedEntryNames" multiplicity="(0 -1)" elementType="java.lang.String"
	 */
	private Set addedEntryNames = new HashSet();

	
	/**
	 * Create a new instance.
	 * 
	 * @param out
	 * @throws java.io.IOException
	 */
	public EntryTrackingJarOutputStream(OutputStream out) throws IOException {
		super(out);
	}

	/**
	 * Create a new instance.
	 * 
	 * @param out
	 * @param man
	 * @throws java.io.IOException
	 */
	public EntryTrackingJarOutputStream(OutputStream out, Manifest man)
		throws IOException 
	{
		super(out);
		addManifest(man);
	}
	
	/**
	 * Return a boolean indicating whether the specified
	 * entry has already been added to the output stream.
	 * 
	 * @param ze
	 * @return
	 */
	public boolean alreadyAdded(ZipEntry ze) {
		return addedEntryNames.contains(ze.getName());
	}
	
	/**
	 * @see java.util.zip.ZipOutputStream#putNextEntry(java.util.zip.ZipEntry)
	 */
	public void putNextEntry(ZipEntry ze) throws IOException {
		super.putNextEntry(ze);
		addedEntryNames.add(ze.getName());
	}
	
	/**
	 * Add the manifest to the output stream.
	 * 
	 * @param man
	 * @throws IOException
	 */
	private void addManifest(Manifest man) throws IOException {
		if (man == null) {
		    throw new NullPointerException("man");
		}
		
		ZipEntry e = new ZipEntry(JarFile.MANIFEST_NAME);
		putNextEntry(e);
		man.write(new BufferedOutputStream(this));
		closeEntry();
	}
}

⌨️ 快捷键说明

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