< prev index next >

src/java.datatransfer/share/classes/java/awt/datatransfer/MimeType.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 24,96 **** */ package java.awt.datatransfer; import java.io.Externalizable; - import java.io.ObjectOutput; - import java.io.ObjectInput; import java.io.IOException; ! import java.util.Enumeration; import java.util.Locale; - /** ! * A Multipurpose Internet Mail Extension (MIME) type, as defined ! * in RFC 2045 and 2046. ! * ! * THIS IS *NOT* - REPEAT *NOT* - A PUBLIC CLASS! DataFlavor IS ! * THE PUBLIC INTERFACE, AND THIS IS PROVIDED AS A ***PRIVATE*** ! * (THAT IS AS IN *NOT* PUBLIC) HELPER CLASS! */ class MimeType implements Externalizable, Cloneable { /* * serialization support */ static final long serialVersionUID = -6568722458793895906L; /** ! * Constructor for externalization; this constructor should not be ! * called directly by an application, since the result will be an ! * uninitialized, immutable <code>MimeType</code> object. */ public MimeType() { } /** ! * Builds a <code>MimeType</code> from a <code>String</code>. * ! * @param rawdata text used to initialize the <code>MimeType</code> ! * @throws NullPointerException if <code>rawdata</code> is null */ public MimeType(String rawdata) throws MimeTypeParseException { parse(rawdata); } /** ! * Builds a <code>MimeType</code> with the given primary and sub ! * type but has an empty parameter list. * ! * @param primary the primary type of this <code>MimeType</code> ! * @param sub the subtype of this <code>MimeType</code> ! * @throws NullPointerException if either <code>primary</code> or ! * <code>sub</code> is null */ public MimeType(String primary, String sub) throws MimeTypeParseException { this(primary, sub, new MimeTypeParameterList()); } /** ! * Builds a <code>MimeType</code> with a pre-defined ! * and valid (or empty) parameter list. * ! * @param primary the primary type of this <code>MimeType</code> ! * @param sub the subtype of this <code>MimeType</code> * @param mtpl the requested parameter list ! * @throws NullPointerException if either <code>primary</code>, ! * <code>sub</code> or <code>mtpl</code> is null */ public MimeType(String primary, String sub, MimeTypeParameterList mtpl) throws MimeTypeParseException { // check to see if primary is valid if(isValidToken(primary)) { --- 24,94 ---- */ package java.awt.datatransfer; import java.io.Externalizable; import java.io.IOException; ! import java.io.ObjectInput; ! import java.io.ObjectOutput; import java.util.Locale; /** ! * A Multipurpose Internet Mail Extension (MIME) type, as defined in RFC 2045 ! * and 2046. ! * <p> ! * THIS IS *NOT* - REPEAT *NOT* - A PUBLIC CLASS! DataFlavor IS THE PUBLIC ! * INTERFACE, AND THIS IS PROVIDED AS A ***PRIVATE*** (THAT IS AS IN *NOT* ! * PUBLIC) HELPER CLASS! */ class MimeType implements Externalizable, Cloneable { /* * serialization support */ static final long serialVersionUID = -6568722458793895906L; /** ! * Constructor for externalization; this constructor should not be called ! * directly by an application, since the result will be an uninitialized, ! * immutable {@code MimeType} object. */ public MimeType() { } /** ! * Builds a {@code MimeType} from a {@code String}. * ! * @param rawdata text used to initialize the {@code MimeType} ! * @throws NullPointerException if {@code rawdata} is {@code null} */ public MimeType(String rawdata) throws MimeTypeParseException { parse(rawdata); } /** ! * Builds a {@code MimeType} with the given primary and sub type but has an ! * empty parameter list. * ! * @param primary the primary type of this {@code MimeType} ! * @param sub the subtype of this {@code MimeType} ! * @throws NullPointerException if either {@code primary} or {@code sub} is ! * {@code null} */ public MimeType(String primary, String sub) throws MimeTypeParseException { this(primary, sub, new MimeTypeParameterList()); } /** ! * Builds a {@code MimeType} with a pre-defined and valid (or empty) ! * parameter list. * ! * @param primary the primary type of this {@code MimeType} ! * @param sub the subtype of this {@code MimeType} * @param mtpl the requested parameter list ! * @throws NullPointerException if either {@code primary}, {@code sub} or ! * {@code mtpl} is {@code null} */ public MimeType(String primary, String sub, MimeTypeParameterList mtpl) throws MimeTypeParseException { // check to see if primary is valid if(isValidToken(primary)) {
*** 119,135 **** code += parameters.hashCode(); return code; } // hashCode() /** ! * <code>MimeType</code>s are equal if their primary types, ! * subtypes, and parameters are all equal. No default values ! * are taken into account. ! * @param thatObject the object to be evaluated as a ! * <code>MimeType</code> ! * @return <code>true</code> if <code>thatObject</code> is ! * a <code>MimeType</code>; otherwise returns <code>false</code> */ public boolean equals(Object thatObject) { if (!(thatObject instanceof MimeType)) { return false; } --- 117,132 ---- code += parameters.hashCode(); return code; } // hashCode() /** ! * {@code MimeType}s are equal if their primary types, subtypes, and ! * parameters are all equal. No default values are taken into account. ! * ! * @param thatObject the object to be evaluated as a {@code MimeType} ! * @return {@code true} if {@code thatObject} is a {@code MimeType}; ! * otherwise returns {@code false} */ public boolean equals(Object thatObject) { if (!(thatObject instanceof MimeType)) { return false; }
*** 142,152 **** } // equals() /** * A routine for parsing the MIME type out of a String. * ! * @throws NullPointerException if <code>rawdata</code> is null */ private void parse(String rawdata) throws MimeTypeParseException { int slashIndex = rawdata.indexOf('/'); int semIndex = rawdata.indexOf(';'); if((slashIndex < 0) && (semIndex < 0)) { --- 139,149 ---- } // equals() /** * A routine for parsing the MIME type out of a String. * ! * @throws NullPointerException if {@code rawdata} is {@code null} */ private void parse(String rawdata) throws MimeTypeParseException { int slashIndex = rawdata.indexOf('/'); int semIndex = rawdata.indexOf(';'); if((slashIndex < 0) && (semIndex < 0)) {
*** 211,222 **** public MimeTypeParameterList getParameters() { return (MimeTypeParameterList)parameters.clone(); } /** ! * Retrieve the value associated with the given name, or null if there ! * is no current association. */ public String getParameter(String name) { return parameters.get(name); } --- 208,219 ---- public MimeTypeParameterList getParameters() { return (MimeTypeParameterList)parameters.clone(); } /** ! * Retrieve the value associated with the given name, or {@code null} if ! * there is no current association. */ public String getParameter(String name) { return parameters.get(name); }
*** 245,271 **** public String toString() { return getBaseType() + parameters.toString(); } /** ! * Return a String representation of this object ! * without the parameter list. */ public String getBaseType() { return primaryType + "/" + subType; } /** ! * Returns <code>true</code> if the primary type and the ! * subtype of this object are the same as the specified ! * <code>type</code>; otherwise returns <code>false</code>. ! * ! * @param type the type to compare to <code>this</code>'s type ! * @return <code>true</code> if the primary type and the ! * subtype of this object are the same as the ! * specified <code>type</code>; otherwise returns ! * <code>false</code> */ public boolean match(MimeType type) { if (type == null) return false; return primaryType.equals(type.getPrimaryType()) --- 242,266 ---- public String toString() { return getBaseType() + parameters.toString(); } /** ! * Return a String representation of this object without the parameter list. */ public String getBaseType() { return primaryType + "/" + subType; } /** ! * Returns {@code true} if the primary type and the subtype of this object ! * are the same as the specified {@code type}; otherwise returns ! * {@code false}. ! * ! * @param type the type to compare to {@code this}'s type ! * @return {@code true} if the primary type and the subtype of this object ! * are the same as the specified {@code type}; otherwise returns ! * {@code false} */ public boolean match(MimeType type) { if (type == null) return false; return primaryType.equals(type.getPrimaryType())
*** 273,306 **** || type.getSubType().equals("*") || (subType.equals(type.getSubType()))); } /** ! * Returns <code>true</code> if the primary type and the ! * subtype of this object are the same as the content type ! * described in <code>rawdata</code>; otherwise returns ! * <code>false</code>. * * @param rawdata the raw data to be examined ! * @return <code>true</code> if the primary type and the ! * subtype of this object are the same as the content type ! * described in <code>rawdata</code>; otherwise returns ! * <code>false</code>; if <code>rawdata</code> is ! * <code>null</code>, returns <code>false</code> */ public boolean match(String rawdata) throws MimeTypeParseException { if (rawdata == null) return false; return match(new MimeType(rawdata)); } /** ! * The object implements the writeExternal method to save its contents ! * by calling the methods of DataOutput for its primitive values or ! * calling the writeObject method of ObjectOutput for objects, strings ! * and arrays. ! * @exception IOException Includes any I/O exceptions that may occur */ public void writeExternal(ObjectOutput out) throws IOException { String s = toString(); // contains ASCII chars only // one-to-one correspondence between ASCII char and byte in UTF string if (s.length() <= 65535) { // 65535 is max length of UTF string --- 268,299 ---- || type.getSubType().equals("*") || (subType.equals(type.getSubType()))); } /** ! * Returns {@code true} if the primary type and the subtype of this object ! * are the same as the content type described in {@code rawdata}; otherwise ! * returns {@code false}. * * @param rawdata the raw data to be examined ! * @return {@code true} if the primary type and the subtype of this object ! * are the same as the content type described in {@code rawdata}; ! * otherwise returns {@code false}; if {@code rawdata} is ! * {@code null}, returns {@code false} */ public boolean match(String rawdata) throws MimeTypeParseException { if (rawdata == null) return false; return match(new MimeType(rawdata)); } /** ! * The object implements the writeExternal method to save its contents by ! * calling the methods of DataOutput for its primitive values or calling the ! * writeObject method of ObjectOutput for objects, strings and arrays. ! * ! * @throws IOException Includes any I/O exceptions that may occur */ public void writeExternal(ObjectOutput out) throws IOException { String s = toString(); // contains ASCII chars only // one-to-one correspondence between ASCII char and byte in UTF string if (s.length() <= 65535) { // 65535 is max length of UTF string
*** 312,328 **** out.write(s.getBytes()); } } /** ! * The object implements the readExternal method to restore its ! * contents by calling the methods of DataInput for primitive ! * types and readObject for objects, strings and arrays. The ! * readExternal method must read the values in the same sequence ! * and with the same types as were written by writeExternal. ! * @exception ClassNotFoundException If the class for an object being ! * restored cannot be found. */ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { String s = in.readUTF(); if (s == null || s.length() == 0) { // long mime type --- 305,322 ---- out.write(s.getBytes()); } } /** ! * The object implements the readExternal method to restore its contents by ! * calling the methods of DataInput for primitive types and readObject for ! * objects, strings and arrays. The readExternal method must read the values ! * in the same sequence and with the same types as were written by ! * writeExternal. ! * ! * @throws ClassNotFoundException If the class for an object being restored ! * cannot be found */ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { String s = in.readUTF(); if (s == null || s.length() == 0) { // long mime type
*** 337,349 **** } } /** * Returns a clone of this object. * @return a clone of this object */ - public Object clone() { MimeType newObj = null; try { newObj = (MimeType)super.clone(); } catch (CloneNotSupportedException cannotHappen) { --- 331,343 ---- } } /** * Returns a clone of this object. + * * @return a clone of this object */ public Object clone() { MimeType newObj = null; try { newObj = (MimeType)super.clone(); } catch (CloneNotSupportedException cannotHappen) {
*** 366,376 **** } /** * Determines whether or not a given string is a legal token. * ! * @throws NullPointerException if <code>s</code> is null */ private boolean isValidToken(String s) { int len = s.length(); if(len > 0) { for (int i = 0; i < len; ++i) { --- 360,370 ---- } /** * Determines whether or not a given string is a legal token. * ! * @throws NullPointerException if {@code s} is {@code null} */ private boolean isValidToken(String s) { int len = s.length(); if(len > 0) { for (int i = 0; i < len; ++i) {
*** 386,394 **** } /** * A string that holds all the special chars. */ - private static final String TSPECIALS = "()<>@,;:\\\"/[]?="; - } // class MimeType --- 380,386 ----
< prev index next >