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

📄 uninstjar.java

📁 有关java 的p2p应用,是一般很好的教程,有兴趣的朋友应该好好阅读一下
💻 JAVA
字号:
/* * Copyright (c) 2001 Sun Microsystems, Inc.  All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. The end-user documentation included with the redistribution, *    if any, must include the following acknowledgment: *       "This product includes software developed by the *       Sun Microsystems, Inc. for Project JXTA." *    Alternately, this acknowledgment may appear in the software itself, *    if and wherever such third-party acknowledgments normally appear. * * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact Project JXTA at http://www.jxta.org. * * 5. Products derived from this software may not be called "JXTA", *    nor may "JXTA" appear in their name, without prior written *    permission of Sun. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL SUN MICROSYSTEMS OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of Project JXTA.  For more * information on Project JXTA, please see * <http://www.jxta.org/>. * * This license is based on the BSD license adopted by the Apache Foundation. * * $Id: uninstjar.java,v 1.7 2004/05/20 00:16:50 bondolo Exp $ */package net.jxta.impl.shell.bin.uninstjar;import net.jxta.impl.shell.*;import java.io.*;import java.util.*;import java.net.*;import net.jxta.pipe.*;import net.jxta.peergroup.*;import net.jxta.peer.*;import net.jxta.document.*;import net.jxta.id.*;/** * 'uninstjar' Shell command to remove installed commands contained in the jar-file to be uninstalled. */public class uninstjar extends ShellApp {	protected List instJarList;	protected ShellCmds cmds;	    public int startApp (String[] args) {		if (args.length == 0) {		    return syntaxError();		}        cmds = new ShellCmds(getEnv());				// Construct a list containing all installed files (if any)        instJarList = new ArrayList( Arrays.asList(cmds.getInstJars()) );		// Check whether the environment variable contains files		if (instJarList.isEmpty()) {			return noJarsInstalledError();		}				// Check if we must uninstall all files		if (args[0].equals("-all")) {			List toRemoveList = new ArrayList( instJarList );			uninstallJars(toRemoveList);		} else {	        // Construct list containing all File objects to be removed.	        Vector toRemoveList = new Vector();	        for (int i = 0, max = instJarList.size() - 1; i < args.length; i++) {	        	// Check for index parameter.	        	if (args[i].equals("-i")) {		        	// Test whether the neccessary index argument exists.			        if (++i >= args.length) {			        	println("Error: Missing index argument!");			        	break;				    }				    // Add file with parsed index argument to toRemoveList.				    try {				        int index = Integer.parseInt(args[i]);				        if (index < 0 || index > max) {					    	println("Error: '" + index + "' out of range [0.." + max + "]!");						    continue;						}				        toRemoveList.addElement(instJarList.get(index));				    } catch (NumberFormatException e) {						println("Error: '" + args[i] + "' is not a valid number!");				    }				} else				// Check for file parameter.				if (args[i].equals("-f")) {		        	// Test whether the neccessary file argument exists.			        if (++i >= args.length) {			        	println("Error: Missing file argument!");			        	break;				    }					// Add corresponding File object to toRemoveList.					File file = new File(args[i]);		        	if (instJarList.contains(file)) {			        	toRemoveList.addElement(file);				    } else {				    	println("Error: '" + file + "' not found!");					}				} else {					println("Error: Unknown parameter '" + args[i] + "'!");				}	        }	        // Remove all files contained in toRemoveList.	        uninstallJars(toRemoveList);	    }        // Set the new value of environment variable INST_JARS.        cmds.setInstJars(instJarList);                return ShellApp.appNoError;	}    private int syntaxError () {	    println ("Usage: uninstjar <-all | -f jar-file | -i index> [<-f jar-file | -i index> [...]]");	    return ShellApp.appParamError;    }	private int noJarsInstalledError() {		println("Error: No jar-files installed!");		return ShellApp.appMiscError;	}		/**	 * Removes a file from the list of installed jars.	 *	 * @param	file	the file to be uninstalled.	 */	protected void uninstallJar(File file) {		instJarList.remove(file);	}		/**	 * Uninstalls a given list of File objects from the list of installed jar-files.	 *	 * @param	list	URLs to be removed.	 */	protected void uninstallJars(List list) {		for (Iterator e = list.iterator(); e.hasNext();) {			uninstallJar((File)e.next());		}	}		/**	 * Returns a short description for this command (used by the Shell command 'man').	 */	public String getDescription() {		return "Uninstalls jar-files previously installed with 'instjar'";	}		/**	 * Prints the help text.	 */    public void help() {      println("NAME");      println("     uninstjar - uninstalls one or more jar-files previously");      println("     installed with the command 'instjar'.");      println(" ");       println("SYNOPSIS");      println("     uninstjar <-all | -f file | -i index> [<-f file | -i index> [...]]");      println(" ");      println("DESCRIPTION");      println(" ");      println("This command uninstalls previously installed jar-files containing");      println("additional Shell commands. Once uninstalled, the commands placed");      println("in that jar-file are no longer available to the Shell.");      println("An arbirtary number of jar-files to uninstall can be supplied.");      println("Either through supplying the path to the jar-file itself or through");      println("their indices, which can be obtained through invoking 'instjars'");      println("with no arguments. The list of installed urls is stored in the environment");      println("variable '" + ShellCmds.INST_JARS + "'.");      println("So uninstalling means removing the corresponding entry from this");      println("environment variable.");      println(" ");      println("EXAMPLE");      println(" ");      println("To uninstall a jar-file by supplying the path:");      println("    JXTA>uninstjar -f c:/userlib/usrcmds.jar");      println(" ");      println("To uninstall a jar-file by its index first list all installed");      println("jar-files with 'instjar':");      println("    JXTA> instjar");      println("    0 c:/userlib/usrcmds.jar");      println("    1 c:/userlib/toolcmds.jar");      println("Now uninstall a jar-file with its index:");      println("    JXTA>uninstjar -i 1");      println(" ");      println("To uninstall all jar-files:");      println("    JXTA>uninstjar -all");      println(" ");      println("SEE ALSO");      println("    instjar ");    }}

⌨️ 快捷键说明

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