325N/A * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. 325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 325N/A * This code is free software; you can redistribute it and/or modify it 325N/A * under the terms of the GNU General Public License version 2 only, as 325N/A * published by the Free Software Foundation. Oracle designates this 325N/A * particular file as subject to the "Classpath" exception as provided 325N/A * by Oracle in the LICENSE file that accompanied this code. 325N/A * This code is distributed in the hope that it will be useful, but WITHOUT 325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 325N/A * version 2 for more details (a copy is included in the LICENSE file that 325N/A * accompanied this code). 325N/A * You should have received a copy of the GNU General Public License version 325N/A * 2 along with this work; if not, write to the Free Software Foundation, 325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 325N/A * or visit www.oracle.com if you need additional information or have any 325N/A * A Multipurpose Internet Mail Extension (MIME) type, as defined 325N/A * in RFC 2045 and 2046. 325N/A * A string that holds all the special chars. 325N/A * Constructor that builds a MimeType from a String. 325N/A * @param rawdata the MIME type string 325N/A * Constructor that builds a MimeType with the given primary and sub type 325N/A * but has an empty parameter list. 325N/A * @param primary the primary MIME type 325N/A * @param sub the MIME sub-type 325N/A * @exception MimeTypeParseException if the primary type or subtype 325N/A // check to see if primary is valid 325N/A // check to see if sub is valid 325N/A * A routine for parsing the MIME type out of a String. 325N/A // neither character is present, so treat it 325N/A // we have a ';' (and therefore a parameter list), 325N/A // but no '/' indicating a sub type is present 325N/A // we have a primary and sub type but no parameter list 325N/A // we have all three items in the proper sequence 325N/A // we have a ';' lexically before a '/' which means we 325N/A // have a primary type and a parameter list but no sub type 325N/A // now validate the primary and sub types 325N/A // check to see if primary is valid 325N/A // check to see if sub is valid 325N/A * Retrieve the primary type of this object. 325N/A * @return the primary MIME type 325N/A * Set the primary type for this object to the given String. 325N/A * @param primary the primary MIME type 325N/A * @exception MimeTypeParseException if the primary type 325N/A // check to see if primary is valid 325N/A * Retrieve the subtype of this object. 325N/A * @return the MIME subtype 325N/A * Set the subtype for this object to the given String. 325N/A * @param sub the MIME subtype 325N/A * @exception MimeTypeParseException if the subtype 325N/A // check to see if sub is valid 325N/A * Retrieve this object's parameter list. 325N/A * @return a MimeTypeParameterList object representing the parameters 325N/A * Retrieve the value associated with the given name, or null if there 325N/A * is no current association. 325N/A * @param name the parameter name 325N/A * @return the paramter's value 325N/A * Set the value to be associated with the given name, replacing 325N/A * any previous association. 325N/A * @param name the parameter name 325N/A * @param value the paramter's value 325N/A * Remove any value associated with the given name. 325N/A * @param name the parameter name 325N/A * Return the String representation of this object. 325N/A * Return a String representation of this object 325N/A * without the parameter list. 325N/A * @return the MIME type and sub-type 325N/A * Determine if the primary and sub type of this object is 325N/A * the same as what is in the given type. 325N/A * @param type the MimeType object to compare with 325N/A * @return true if they match 325N/A * Determine if the primary and sub type of this object is 325N/A * the same as the content type described in rawdata. 325N/A * @param rawdata the MIME type string to compare with 325N/A * @return true if they match 325N/A * The object implements the writeExternal method to save its contents 325N/A * by calling the methods of DataOutput for its primitive values or 325N/A * calling the writeObject method of ObjectOutput for objects, strings 325N/A * @param out the ObjectOutput object to write to 325N/A * @exception IOException Includes any I/O exceptions that may occur 325N/A * The object implements the readExternal method to restore its 325N/A * contents by calling the methods of DataInput for primitive 325N/A * types and readObject for objects, strings and arrays. The 325N/A * readExternal method must read the values in the same sequence 325N/A * and with the same types as were written by writeExternal. 325N/A * @param in the ObjectInput object to read from 325N/A * @exception ClassNotFoundException If the class for an object being 325N/A * restored cannot be found. 325N/A // below here be scary parsing related things 325N/A * Determine whether or not a given character belongs to a legal token. 325N/A * Determine whether or not a given string is a legal token. 325N/A * A simple parser test, 325N/A public static void main(String[] args) 325N/A throws MimeTypeParseException, IOException { 325N/A for (int i = 0; i < args.length; ++i) { 325N/A System.out.println("Original: " + args[i]); 325N/A MimeType type = new MimeType(args[i]); 325N/A System.out.println("Short: " + type.getBaseType()); 325N/A System.out.println("Parsed: " + type.toString());