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

📄 attributes.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	// write out all attributes except for the version	// we wrote out earlier	Iterator it = entrySet().iterator();	while (it.hasNext()) {	    Map.Entry e = (Map.Entry)it.next();	    String name = ((Name)e.getKey()).toString();	    if ((version != null) && ! (name.equalsIgnoreCase(vername))) {                StringBuffer buffer = new StringBuffer(name);		buffer.append(": ");                String value = (String)e.getValue();                if (value != null) {                    byte[] vb = value.getBytes("UTF8");                    value = new String(vb, 0, 0, vb.length);                }                buffer.append(value);		buffer.append("\r\n");                Manifest.make72Safe(buffer);                out.writeBytes(buffer.toString());	    }	}	out.writeBytes("\r\n");    }    /*     * Reads attributes from the specified input stream.     * XXX Need to handle UTF8 values.     */    void read(Manifest.FastInputStream is, byte[] lbuf) throws IOException {	String name = null, value = null;        byte[] lastline = null;	int len;	while ((len = is.readLine(lbuf)) != -1) {            boolean lineContinued = false;	    if (lbuf[--len] != '\n') {		throw new IOException("line too long");	    }	    if (len > 0 && lbuf[len-1] == '\r') {		--len;	    }	    if (len == 0) {		break;	    }	    int i = 0;	    if (lbuf[0] == ' ') {		// continuation of previous line		if (name == null) {		    throw new IOException("misplaced continuation line");		}                lineContinued = true;                byte[] buf = new byte[lastline.length + len - 1];                System.arraycopy(lastline, 0, buf, 0, lastline.length);                System.arraycopy(lbuf, 1, buf, lastline.length, len - 1);                if (is.peek() == ' ') {                    lastline = buf;                    continue;                }		value = new String(buf, 0, buf.length, "UTF8");                lastline = null;	    } else {                while (lbuf[i++] != ':') {                    if (i >= len) {			throw new IOException("invalid header field");                    }                }                if (lbuf[i++] != ' ') {		    throw new IOException("invalid header field");                }                name = new String(lbuf, 0, 0, i - 2);                if (is.peek() == ' ') {                    lastline = new byte[len - i];                    System.arraycopy(lbuf, i, lastline, 0, len - i);                    continue;                }                value = new String(lbuf, i, len - i, "UTF8");            }	    try {		if ((putValue(name, value) != null) && (!lineContinued)) {                    Logger.getLogger("java.util.jar").warning(                                     "Duplicate name in Manifest: " + name);                } 	    } catch (IllegalArgumentException e) {		throw new IOException("invalid header field name: " + name);	    }	}    }    /**     * The Attributes.Name class represents an attribute name stored in     * this Map. Valid attribute names are case-insensitive, are restricted      * to the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed      * 70 characters in length. Attribute values can contain any characters      * and will be UTF8-encoded when written to the output stream.  See the      * <a href="../../../../guide/jar/jar.html">JAR File Specification</a>      * for more information about valid attribute names and values.     */    public static class Name {	private String name;	private int hashCode = -1;	/**	 * Constructs a new attribute name using the given string name.	 *	 * @param name the attribute string name	 * @exception IllegalArgumentException if the attribute name was	 *            invalid	 * @exception NullPointerException if the attribute name was null	 */	public Name(String name) {	    if (name == null) {		throw new NullPointerException("name");	    }	    if (!isValid(name)) {		throw new IllegalArgumentException(name);	    }	    this.name = name.intern();	}	private static boolean isValid(String name) {	    int len = name.length();	    if (len > 70 || len == 0) {		return false;	    }	    for (int i = 0; i < len; i++) {		if (!isValid(name.charAt(i))) {		    return false;		}	    }	    return true;	}	private static boolean isValid(char c) {	    return isAlpha(c) || isDigit(c) || c == '_' || c == '-';	}	private static boolean isAlpha(char c) {	    return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');	}	private static boolean isDigit(char c) {	    return c >= '0' && c <= '9';	}	/**	 * Compares this attribute name to another for equality.	 * @param o the object to compare         * @return true if this attribute name is equal to the         *         specified attribute object	 */	public boolean equals(Object o) {	    if (o instanceof Name) {		return name.equalsIgnoreCase(((Name)o).name);	    } else {		return false;	    }	}      	/**	 * Computes the hash value for this attribute name.	 */        public int hashCode() {	    if (hashCode == -1) {		hashCode = name.toLowerCase().hashCode();	    }	    return hashCode;	}	/**	 * Returns the attribute name as a String.	 */	public String toString() {	    return name;	}        /**         * <code>Name</code> object for <code>Manifest-Version</code>          * manifest attribute. This attribute indicates the version number          * of the manifest standard to which a JAR file's manifest conforms.         * @see <a href="../../../../guide/jar/jar.html#JAR Manifest">         *      Manifest and Signature Specification</a>         */         public static final Name MANIFEST_VERSION = new Name("Manifest-Version");        /**         * <code>Name</code> object for <code>Signature-Version</code>          * manifest attribute used when signing JAR files.         * @see <a href="../../../../guide/jar/jar.html#JAR Manifest">         *      Manifest and Signature Specification</a>         */                     public static final Name SIGNATURE_VERSION = new Name("Signature-Version");        /**         * <code>Name</code> object for <code>Content-Type</code>          * manifest attribute.         */                       public static final Name CONTENT_TYPE = new Name("Content-Type");        /**         * <code>Name</code> object for <code>Class-Path</code>          * manifest attribute. Bundled extensions can use this attribute          * to find other JAR files containing needed classes.         * @see <a href="../../../../guide/extensions/spec.html#bundled">         *      Extensions Specification</a>         */           public static final Name CLASS_PATH = new Name("Class-Path");        /**         * <code>Name</code> object for <code>Main-Class</code> manifest          * attribute used for launching applications packaged in JAR files.          * The <code>Main-Class</code> attribute is used in conjunction          * with the <code>-jar</code> command-line option of the          * <tt>java</tt> application launcher.         */         public static final Name MAIN_CLASS = new Name("Main-Class");        /**         * <code>Name</code> object for <code>Sealed</code> manifest attribute          * used for sealing.         * @see <a href="../../../../guide/extensions/spec.html#sealing">         *      Extension Sealing</a>         */         public static final Name SEALED = new Name("Sealed");       /**         * <code>Name</code> object for <code>Extension-List</code> manifest attribute          * used for declaring dependencies on installed extensions.         * @see <a href="../../../../guide/extensions/spec.html#dependnecy">         *      Installed extension dependency</a>         */         public static final Name EXTENSION_LIST = new Name("Extension-List");        /**         * <code>Name</code> object for <code>Extension-Name</code> manifest attribute          * used for declaring dependencies on installed extensions.         * @see <a href="../../../../guide/extensions/spec.html#dependency">         *      Installed extension dependency</a>         */         public static final Name EXTENSION_NAME = new Name("Extension-Name");        /**         * <code>Name</code> object for <code>Extension-Name</code> manifest attribute          * used for declaring dependencies on installed extensions.         * @see <a href="../../../../guide/extensions/spec.html#dependency">         *      Installed extension dependency</a>         */         public static final Name EXTENSION_INSTALLATION = new Name("Extension-Installation");        /**         * <code>Name</code> object for <code>Implementation-Title</code>          * manifest attribute used for package versioning.         * @see <a href="../../../../guide/versioning/spec/VersioningSpecification.html#PackageVersioning">         *      Java Product Versioning Specification</a>         */        public static final Name IMPLEMENTATION_TITLE = new Name("Implementation-Title");        /**         * <code>Name</code> object for <code>Implementation-Version</code>          * manifest attribute used for package versioning.         * @see <a href="../../../../guide/versioning/spec/VersioningSpecification.html#PackageVersioning">         *      Java Product Versioning Specification</a>         */        public static final Name IMPLEMENTATION_VERSION = new Name("Implementation-Version");        /**         * <code>Name</code> object for <code>Implementation-Vendor</code>          * manifest attribute used for package versioning.         * @see <a href="../../../../guide/versioning/spec/VersioningSpecification.html#PackageVersioning">         *      Java Product Versioning Specification</a>         */        public static final Name IMPLEMENTATION_VENDOR = new Name("Implementation-Vendor");	/**         * <code>Name</code> object for <code>Implementation-Vendor-Id</code>          * manifest attribute used for package versioning.         * @see <a href="../../../../guide/versioning/spec/VersioningSpecification.html#PackageVersioning">         *      Java Product Versioning Specification</a>         */        public static final Name IMPLEMENTATION_VENDOR_ID = new Name("Implementation-Vendor-Id");       /**         * <code>Name</code> object for <code>Implementation-Vendor-URL</code>          * manifest attribute used for package versioning.         * @see <a href="../../../../guide/versioning/spec/VersioningSpecification.html#PackageVersioning">         *      Java Product Versioning Specification</a>         */        public static final Name IMPLEMENTATION_URL = new Name("Implementation-URL");        /**         * <code>Name</code> object for <code>Specification-Title</code>          * manifest attribute used for package versioning.         * @see <a href="../../../../guide/versioning/spec/VersioningSpecification.html#PackageVersioning">         *      Java Product Versioning Specification</a>         */        public static final Name SPECIFICATION_TITLE = new Name("Specification-Title");        /**         * <code>Name</code> object for <code>Specification-Version</code>          * manifest attribute used for package versioning.         * @see <a href="../../../../guide/versioning/spec/VersioningSpecification.html#PackageVersioning">         *      Java Product Versioning Specification</a>         */        public static final Name SPECIFICATION_VERSION = new Name("Specification-Version");        /**         * <code>Name</code> object for <code>Specification-Vendor</code>          * manifest attribute used for package versioning.         * @see <a href="../../../../guide/versioning/spec/VersioningSpecification.html#PackageVersioning">         *      Java Product Versioning Specification</a>         */        public static final Name SPECIFICATION_VENDOR = new Name("Specification-Vendor");    }}

⌨️ 快捷键说明

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