< prev index next >

jaxws/src/java.activation/share/classes/javax/activation/MimeType.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  41     private MimeTypeParameterList parameters;
  42 
  43     /**
  44      * A string that holds all the special chars.
  45      */
  46     private static final String TSPECIALS = "()<>@,;:/[]?=\\\"";
  47 
  48     /**
  49      * Default constructor.
  50      */
  51     public MimeType() {
  52         primaryType = "application";
  53         subType = "*";
  54         parameters = new MimeTypeParameterList();
  55     }
  56 
  57     /**
  58      * Constructor that builds a MimeType from a String.
  59      *
  60      * @param rawdata   the MIME type string

  61      */
  62     public MimeType(String rawdata) throws MimeTypeParseException {
  63         parse(rawdata);
  64     }
  65 
  66     /**
  67      * Constructor that builds a MimeType with the given primary and sub type
  68      * but has an empty parameter list.
  69      *
  70      * @param primary   the primary MIME type
  71      * @param sub       the MIME sub-type
  72      * @exception       MimeTypeParseException  if the primary type or subtype
  73      *                                          is not a valid token
  74      */
  75     public MimeType(String primary, String sub) throws MimeTypeParseException {
  76         //    check to see if primary is valid
  77         if (isValidToken(primary)) {
  78             primaryType = primary.toLowerCase(Locale.ENGLISH);
  79         } else {
  80             throw new MimeTypeParseException("Primary type is invalid.");


 241     /**
 242      * Determine if the primary and sub type of this object is
 243      * the same as what is in the given type.
 244      *
 245      * @param type      the MimeType object to compare with
 246      * @return          true if they match
 247      */
 248     public boolean match(MimeType type) {
 249         return primaryType.equals(type.getPrimaryType())
 250                     && (subType.equals("*")
 251                             || type.getSubType().equals("*")
 252                             || (subType.equals(type.getSubType())));
 253     }
 254 
 255     /**
 256      * Determine if the primary and sub type of this object is
 257      * the same as the content type described in rawdata.
 258      *
 259      * @param rawdata   the MIME type string to compare with
 260      * @return          true if they match

 261      */
 262     public boolean match(String rawdata) throws MimeTypeParseException {
 263         return match(new MimeType(rawdata));
 264     }
 265 
 266     /**
 267      * The object implements the writeExternal method to save its contents
 268      * by calling the methods of DataOutput for its primitive values or
 269      * calling the writeObject method of ObjectOutput for objects, strings
 270      * and arrays.
 271      *
 272      * @param out       the ObjectOutput object to write to
 273      * @exception IOException Includes any I/O exceptions that may occur
 274      */
 275     public void writeExternal(ObjectOutput out) throws IOException {
 276         out.writeUTF(toString());
 277         out.flush();
 278     }
 279 
 280     /**


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  41     private MimeTypeParameterList parameters;
  42 
  43     /**
  44      * A string that holds all the special chars.
  45      */
  46     private static final String TSPECIALS = "()<>@,;:/[]?=\\\"";
  47 
  48     /**
  49      * Default constructor.
  50      */
  51     public MimeType() {
  52         primaryType = "application";
  53         subType = "*";
  54         parameters = new MimeTypeParameterList();
  55     }
  56 
  57     /**
  58      * Constructor that builds a MimeType from a String.
  59      *
  60      * @param rawdata   the MIME type string
  61      * @exception       MimeTypeParseException  if the MIME type can't be parsed
  62      */
  63     public MimeType(String rawdata) throws MimeTypeParseException {
  64         parse(rawdata);
  65     }
  66 
  67     /**
  68      * Constructor that builds a MimeType with the given primary and sub type
  69      * but has an empty parameter list.
  70      *
  71      * @param primary   the primary MIME type
  72      * @param sub       the MIME sub-type
  73      * @exception       MimeTypeParseException  if the primary type or subtype
  74      *                                          is not a valid token
  75      */
  76     public MimeType(String primary, String sub) throws MimeTypeParseException {
  77         //    check to see if primary is valid
  78         if (isValidToken(primary)) {
  79             primaryType = primary.toLowerCase(Locale.ENGLISH);
  80         } else {
  81             throw new MimeTypeParseException("Primary type is invalid.");


 242     /**
 243      * Determine if the primary and sub type of this object is
 244      * the same as what is in the given type.
 245      *
 246      * @param type      the MimeType object to compare with
 247      * @return          true if they match
 248      */
 249     public boolean match(MimeType type) {
 250         return primaryType.equals(type.getPrimaryType())
 251                     && (subType.equals("*")
 252                             || type.getSubType().equals("*")
 253                             || (subType.equals(type.getSubType())));
 254     }
 255 
 256     /**
 257      * Determine if the primary and sub type of this object is
 258      * the same as the content type described in rawdata.
 259      *
 260      * @param rawdata   the MIME type string to compare with
 261      * @return          true if they match
 262      * @exception       MimeTypeParseException  if the MIME type can't be parsed
 263      */
 264     public boolean match(String rawdata) throws MimeTypeParseException {
 265         return match(new MimeType(rawdata));
 266     }
 267 
 268     /**
 269      * The object implements the writeExternal method to save its contents
 270      * by calling the methods of DataOutput for its primitive values or
 271      * calling the writeObject method of ObjectOutput for objects, strings
 272      * and arrays.
 273      *
 274      * @param out       the ObjectOutput object to write to
 275      * @exception IOException Includes any I/O exceptions that may occur
 276      */
 277     public void writeExternal(ObjectOutput out) throws IOException {
 278         out.writeUTF(toString());
 279         out.flush();
 280     }
 281 
 282     /**


< prev index next >