1 /*
   2  * Copyright (c) 2000, 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
  23  * questions.
  24  */
  25 
  26 package javax.print;
  27 
  28 import java.io.IOException;
  29 import java.io.ObjectInputStream;
  30 import java.io.ObjectOutputStream;
  31 import java.io.Serializable;
  32 
  33 
  34 /**
  35  * Class {@code DocFlavor} encapsulates an object that specifies the
  36  * format in which print data is supplied to a {@link DocPrintJob}.
  37  * "Doc" is a short, easy-to-pronounce term that means "a piece of print data."
  38  * The print data format, or "doc flavor", consists of two things:
  39  * <UL>
  40  * <LI>
  41  * <B>MIME type.</B> This is a Multipurpose Internet Mail Extensions (MIME)
  42  * media type (as defined in <A HREF="http://www.ietf.org/rfc/rfc2045.txt">RFC
  43  * 2045</A> and <A HREF="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</A>)
  44  * that specifies how the print data is to be interpreted.
  45  * The charset of text data should be the IANA MIME-preferred name, or its
  46  * canonical name if no preferred name is specified. Additionally a few
  47  * historical names supported by earlier versions of the Java platform may
  48  * be recognized.
  49  * See <a href="../../java/lang/package-summary.html#charenc">
  50  * character encodings</a> for more information on the character encodings
  51  * supported on the Java platform.
  52  *
  53  * <LI>
  54  * <B>Representation class name.</B> This specifies the fully-qualified name of
  55  * the class of the object from which the actual print data comes, as returned
  56  * by the {@link java.lang.Class#getName() Class.getName()} method.
  57  * (Thus the class name for {@code byte[]} is {@code "[B"}, for
  58  * {@code char[]} it is {@code "[C"}.)
  59  * </UL>
  60  * <P>
  61  * A {@code DocPrintJob} obtains its print data by means of interface
  62  * {@link Doc Doc}. A {@code Doc} object lets the {@code DocPrintJob}
  63  * determine the doc flavor the client can supply.  A {@code Doc} object
  64  * also lets the {@code DocPrintJob} obtain an instance of the doc flavor's
  65  * representation class, from which the {@code DocPrintJob} then obtains
  66  * the actual print data.
  67  *
  68  * <HR>
  69  * <H3>Client Formatted Print Data</H3>
  70  * There are two broad categories of print data, client formatted print data
  71  * and service formatted print data.
  72  * <P>
  73  * For <B>client formatted print data</B>, the client determines or knows the
  74  * print data format.
  75  * For example the client may have a JPEG encoded image, a URL for
  76  * HTML code, or a disk file containing plain text in some encoding,
  77  * possibly obtained from an external source, and
  78  * requires a way to describe the data format to the print service.
  79  * <p>
  80  * The doc flavor's representation class is a conduit for the JPS
  81  * {@code DocPrintJob} to obtain a sequence of characters or
  82  * bytes from the client. The
  83  * doc flavor's MIME type is one of the standard media types telling how to
  84  * interpret the sequence of characters or bytes. For a list of standard media
  85  * types, see the Internet Assigned Numbers Authority's (IANA's) <A
  86  * HREF="http://www.iana.org/assignments/media-types/">Media Types
  87  * Directory</A>. Interface {@link Doc Doc} provides two utility operations,
  88  * {@link Doc#getReaderForText() getReaderForText} and
  89  * {@link Doc#getStreamForBytes() getStreamForBytes()}, to help a
  90  * {@code Doc} object's client extract client formatted print data.
  91  * <P>
  92  * For client formatted print data, the print data representation class is
  93  * typically one of the following (although other representation classes are
  94  * permitted):
  95  * <UL>
  96  * <LI>
  97  * Character array ({@code char[]}) -- The print data consists of the
  98  * Unicode characters in the array.
  99  *
 100  * <LI>
 101  * {@code String}  --
 102  * The print data consists of the Unicode characters in the string.
 103  *
 104  * <LI>
 105  * Character stream ({@link java.io.Reader java.io.Reader})
 106  * -- The print data consists of the Unicode characters read from the stream
 107  * up to the end-of-stream.
 108  *
 109  * <LI>
 110  * Byte array ({@code byte[]}) -- The print data consists of the bytes in
 111  * the array. The bytes are encoded in the character set specified by the doc
 112  * flavor's MIME type. If the MIME type does not specify a character set, the
 113  * default character set is US-ASCII.
 114  *
 115  * <LI>
 116  * Byte stream ({@link java.io.InputStream java.io.InputStream}) --
 117  * The print data consists of the bytes read from the stream up to the
 118  * end-of-stream. The bytes are encoded in the character set specified by the
 119  * doc flavor's MIME type. If the MIME type does not specify a character set,
 120  * the default character set is US-ASCII.
 121 
 122  * <LI>
 123  * Uniform Resource Locator ({@link java.net.URL URL})
 124  * -- The print data consists of the bytes read from the URL location.
 125  * The bytes are encoded in the character set specified by the doc flavor's
 126  * MIME type. If the MIME type does not specify a character set, the default
 127  * character set is US-ASCII.
 128  * <P>
 129  * When the representation class is a URL, the print service itself accesses
 130  * and downloads the document directly from its URL address, without involving
 131  * the client. The service may be some form of network print service which
 132  * is executing in a different environment.
 133  * This means you should not use a URL print data flavor to print a
 134  * document at a restricted URL that the client can see but the printer cannot
 135  * see. This also means you should not use a URL print data flavor to print a
 136  * document stored in a local file that is not available at a URL
 137  * accessible independently of the client.
 138  * For example, a file that is not served up by an HTTP server or FTP server.
 139  * To print such documents, let the client open an input stream on the URL
 140  * or file and use an input stream data flavor.
 141  * </UL>
 142  *
 143  * <HR>
 144  * <h3>Default and Platform Encodings</h3>
 145  * <P>
 146  * For byte print data where the doc flavor's MIME type does not include a
 147  * {@code charset} parameter, the Java Print Service instance assumes the
 148  * US-ASCII character set by default. This is in accordance with
 149  * <A HREF="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</A>, which says the
 150  * default character set is US-ASCII. Note that US-ASCII is a subset of
 151  * UTF-8, so in the future this may be widened if a future RFC endorses
 152  * UTF-8 as the default in a compatible manner.
 153  * <p>
 154  * Also note that this is different than the behaviour of the Java runtime
 155  * when interpreting a stream of bytes as text data. That assumes the
 156  * default encoding for the user's locale. Thus, when spooling a file in local
 157  * encoding to a Java Print Service it is important to correctly specify
 158  * the encoding. Developers working in the English locales should
 159  * be particularly conscious of this, as their platform encoding corresponds
 160  * to the default mime charset. By this coincidence that particular
 161  * case may work without specifying the encoding of platform data.
 162  * <p>
 163  * Every instance of the Java virtual machine has a default character encoding
 164  * determined during virtual-machine startup and typically depends upon the
 165  * locale and charset being used by the underlying operating system.
 166  * In a distributed environment there is no guarantee that two VM share
 167  * the same default encoding. Thus clients which want to stream platform
 168  * encoded text data from the host platform to a Java Print Service instance
 169  * must explicitly declare the charset and not rely on defaults.
 170  * <p>
 171  * The preferred form is the official IANA primary name for an encoding.
 172  * Applications which stream text data should always specify the charset
 173  * in the mime type, which necessitates obtaining the encoding of the host
 174  * platform for data (eg files) stored in that platform's encoding.
 175  * A CharSet which corresponds to this and is suitable for use in a
 176  * mime-type for a DocFlavor can be obtained
 177  * from {@link DocFlavor#hostEncoding DocFlavor.hostEncoding}
 178  * This may not always be the primary IANA name but is guaranteed to be
 179  * understood by this VM.
 180  * For common flavors, the pre-defined *HOST DocFlavors may be used.
 181  * <p>
 182  * See <a href="../../java/lang/package-summary.html#charenc">
 183  * character encodings</a> for more information on the character encodings
 184  * supported on the Java platform.
 185  * <HR>
 186  * <h3>Recommended DocFlavors</h3>
 187  * <P>
 188  * The Java Print Service API does not define any mandatorily supported
 189  * DocFlavors.
 190  * However, here are some examples of MIME types that a Java Print Service
 191  * instance might support for client formatted print data.
 192  * Nested classes inside class DocFlavor declare predefined static
 193  * constant DocFlavor objects for these example doc flavors; class DocFlavor's
 194  * constructor can be used to create an arbitrary doc flavor.
 195  * <UL>
 196  * <LI>Preformatted text
 197  * <table class="striped">
 198  * <caption>MIME-Types and their descriptions</caption>
 199  * <thead>
 200  * <TR>
 201  *  <TH>MIME-Type</TH><TH>Description</TH>
 202  * </TR>
 203  * </thead>
 204  * <tbody>
 205  * <TR>
 206  * <TD>{@code "text/plain"}</TD>
 207  * <TD>Plain text in the default character set (US-ASCII)</TD>
 208  * </TR>
 209  * <TR>
 210  * <TD><code>"text/plain; charset=<I>xxx</I>"</code></TD>
 211  * <TD>Plain text in character set <I>xxx</I></TD>
 212  * </TR>
 213  * <TR>
 214  * <TD>{@code "text/html"}</TD>
 215  * <TD>HyperText Markup Language in the default character set (US-ASCII)</TD>
 216  * </TR>
 217  * <TR>
 218  * <TD><code>"text/html; charset=<I>xxx</I>"</code></TD>
 219  * <TD>HyperText Markup Language in character set <I>xxx</I></TD>
 220  * </TR>
 221  * </tbody>
 222  * </TABLE>
 223  * <P>
 224  * In general, preformatted text print data is provided either in a character
 225  * oriented representation class (character array, String, Reader) or in a
 226  * byte oriented representation class (byte array, InputStream, URL).
 227  *
 228  *  <LI>Preformatted page description language (PDL) documents
 229  *
 230  * <table class="striped">
 231  * <caption>MIME-Types and their descriptions</caption>
 232  * <thead>
 233  * <TR>
 234  *  <TH>MIME-Type</TH><TH>Description</TH>
 235  * </TR>
 236  * </thead>
 237  * <tbody>
 238  * <TR>
 239  * <TD>{@code "application/pdf"}</TD>
 240  * <TD>Portable Document Format document</TD>
 241  * </TR>
 242  * <TR>
 243  * <TD>{@code "application/postscript"}</TD>
 244  * <TD>PostScript document</TD>
 245  * </TR>
 246  * <TR>
 247  * <TD>{@code "application/vnd.hp-PCL"}</TD>
 248  * <TD>Printer Control Language document</TD>
 249  * </TR>
 250  * </tbody>
 251  * </TABLE>
 252  * <P>
 253  * In general, preformatted PDL print data is provided in a byte oriented
 254  * representation class (byte array, InputStream, URL).
 255  *
 256  *  <LI>Preformatted images
 257  *
 258  * <table class="striped">
 259  * <caption>MIME-Types and their descriptions</caption>
 260  * <thead>
 261  * <TR>
 262  *  <TH>MIME-Type</TH><TH>Description</TH>
 263  * </TR>
 264  * </thead>
 265  * <tbody>
 266  * <TR>
 267  * <TD>{@code "image/gif"}</TD>
 268  * <TD>Graphics Interchange Format image</TD>
 269  * </TR>
 270  * <TR>
 271  * <TD>{@code "image/jpeg"}</TD>
 272  * <TD>Joint Photographic Experts Group image</TD>
 273  * </TR>
 274  * <TR>
 275  * <TD>{@code "image/png"}</TD>
 276  * <TD>Portable Network Graphics image</TD>
 277  * </TR>
 278  * </tbody>
 279  * </TABLE>
 280  * <P>
 281  * In general, preformatted image print data is provided in a byte oriented
 282  * representation class (byte array, InputStream, URL).
 283  *
 284  *  <LI>Preformatted autosense print data
 285  *
 286  * <table class="striped">
 287  * <caption>MIME-Types and their descriptions</caption>
 288  * <thead>
 289  * <TR>
 290  *  <TH>MIME-Type</TH><TH>Description</TH>
 291  * </TR>
 292  * </thead>
 293  * <tbody>
 294  * <TR>
 295  * <TD>{@code "application/octet-stream"}</TD>
 296  * <TD>The print data format is unspecified (just an octet stream)</TD>
 297  * </TR>
 298  * </tbody>
 299  * </TABLE>
 300  * <P>
 301  * The printer decides how to interpret the print data; the way this
 302  * "autosensing" works is implementation dependent. In general, preformatted
 303  * autosense print data is provided in a byte oriented representation class
 304  * (byte array, InputStream, URL).
 305  * </UL>
 306  *
 307  * <HR>
 308  * <H3>Service Formatted Print Data</H3>
 309  * <P>
 310  * For <B>service formatted print data</B>, the Java Print Service instance
 311  * determines the print data format. The doc flavor's representation class
 312  * denotes an interface whose methods the {@code DocPrintJob} invokes to
 313  * determine the content to be printed -- such as a renderable image
 314  * interface or a Java printable interface.
 315  * The doc flavor's MIME type is the special value
 316  * {@code "application/x-java-jvm-local-objectref"} indicating the client
 317  * will supply a reference to a Java object that implements the interface
 318  * named as the representation class.
 319  * This MIME type is just a placeholder; what's
 320  * important is the print data representation class.
 321  * <P>
 322  * For service formatted print data, the print data representation class is
 323  * typically one of the following (although other representation classes are
 324  * permitted). Nested classes inside class DocFlavor declare predefined static
 325  * constant DocFlavor objects for these example doc flavors; class DocFlavor's
 326  * constructor can be used to create an arbitrary doc flavor.
 327  * <UL>
 328  * <LI>
 329  * Renderable image object -- The client supplies an object that implements
 330  * interface
 331  * {@link java.awt.image.renderable.RenderableImage RenderableImage}. The
 332  * printer calls methods
 333  * in that interface to obtain the image to be printed.
 334  *
 335  * <LI>
 336  * Printable object -- The client supplies an object that implements interface
 337  * {@link java.awt.print.Printable Printable}.
 338  * The printer calls methods in that interface to obtain the pages to be
 339  * printed, one by one.
 340  * For each page, the printer supplies a graphics context, and whatever the
 341  * client draws in that graphics context gets printed.
 342  *
 343  * <LI>
 344  * Pageable object -- The client supplies an object that implements interface
 345  * {@link java.awt.print.Pageable Pageable}. The printer calls
 346  * methods in that interface to obtain the pages to be printed, one by one.
 347  * For each page, the printer supplies a graphics context, and whatever
 348  * the client draws in that graphics context gets printed.
 349  * </UL>
 350  *
 351  * <HR>
 352  *
 353  * <HR>
 354  * <H3>Pre-defined Doc Flavors</H3>
 355  * A Java Print Service instance is not <B><I>required</I></B> to support the
 356  * following print data formats and print data representation classes.  In
 357  * fact, a developer using this class should <b>never</b> assume that a
 358  * particular print service supports the document types corresponding to
 359  * these pre-defined doc flavors.  Always query the print service
 360  * to determine what doc flavors it supports.  However,
 361  * developers who have print services that support these doc flavors are
 362  * encouraged to refer to the predefined singleton instances created here.
 363  * <UL>
 364  * <LI>
 365  * Plain text print data provided through a byte stream. Specifically, the
 366  * following doc flavors are recommended to be supported:
 367  * <BR>·&nbsp;&nbsp;
 368  * {@code ("text/plain", "java.io.InputStream")}
 369  * <BR>·&nbsp;&nbsp;
 370  * {@code ("text/plain; charset=us-ascii", "java.io.InputStream")}
 371  * <BR>·&nbsp;&nbsp;
 372  * {@code ("text/plain; charset=utf-8", "java.io.InputStream")}
 373  *
 374  * <LI>
 375  * Renderable image objects. Specifically, the following doc flavor is
 376  * recommended to be supported:
 377  * <BR>·&nbsp;&nbsp;
 378  * {@code ("application/x-java-jvm-local-objectref", "java.awt.image.renderable.RenderableImage")}
 379  * </UL>
 380  * <P>
 381  * A Java Print Service instance is allowed to support any other doc flavors
 382  * (or none) in addition to the above mandatory ones, at the implementation's
 383  * choice.
 384  * <P>
 385  * Support for the above doc flavors is desirable so a printing client can rely
 386  * on being able to print on any JPS printer, regardless of which doc flavors
 387  * the printer supports. If the printer doesn't support the client's preferred
 388  * doc flavor, the client can at least print plain text, or the client can
 389  * convert its data to a renderable image and print the image.
 390  * <P>
 391  * Furthermore, every Java Print Service instance must fulfill these
 392  * requirements for processing plain text print data:
 393  * <UL>
 394  * <LI>
 395  * The character pair carriage return-line feed (CR-LF) means
 396  * "go to column 1 of the next line."
 397  * <LI>
 398  * A carriage return (CR) character standing by itself means
 399  * "go to column 1 of the next line."
 400  * <LI>
 401  * A line feed (LF) character standing by itself means
 402  * "go to column 1 of the next line."
 403  * </UL>
 404  * <P>
 405  * The client must itself perform all plain text print data formatting not
 406  * addressed by the above requirements.
 407  *
 408  * <H3>Design Rationale</H3>
 409  * <P>
 410  * Class DocFlavor in package javax.print.data is similar to class
 411  * {@link java.awt.datatransfer.DataFlavor DataFlavor}. Class
 412  * {@code DataFlavor}
 413  * is not used in the Java Print Service (JPS) API
 414  * for three reasons which are all rooted in allowing the JPS API to be
 415  * shared by other print services APIs which may need to run on Java profiles
 416  * which do not include all of the Java Platform, Standard Edition.
 417  * <OL TYPE=1>
 418  * <LI>
 419  * The JPS API is designed to be used in Java profiles which do not support
 420  * AWT.
 421  *
 422  * <LI>
 423  * The implementation of class {@code java.awt.datatransfer.DataFlavor}
 424  * does not guarantee that equivalent data flavors will have the same
 425  * serialized representation. DocFlavor does, and can be used in services
 426  * which need this.
 427  *
 428  * <LI>
 429  * The implementation of class {@code java.awt.datatransfer.DataFlavor}
 430  * includes a human presentable name as part of the serialized representation.
 431  * This is not appropriate as part of a service matching constraint.
 432  * </OL>
 433  * <P>
 434  * Class DocFlavor's serialized representation uses the following
 435  * canonical form of a MIME type string. Thus, two doc flavors with MIME types
 436  * that are not identical but that are equivalent (that have the same
 437  * canonical form) may be considered equal.
 438  * <UL>
 439  * <LI> The media type, media subtype, and parameters are retained, but all
 440  *      comments and whitespace characters are discarded.
 441  * <LI> The media type, media subtype, and parameter names are converted to
 442  *      lowercase.
 443  * <LI> The parameter values retain their original case, except a charset
 444  *      parameter value for a text media type is converted to lowercase.
 445  * <LI> Quote characters surrounding parameter values are removed.
 446  * <LI> Quoting backslash characters inside parameter values are removed.
 447  * <LI> The parameters are arranged in ascending order of parameter name.
 448  * </UL>
 449  * <P>
 450  * Class DocFlavor's serialized representation also contains the
 451  * fully-qualified class <I>name</I> of the representation class
 452  * (a String object), rather than the representation class itself
 453  * (a Class object). This allows a client to examine the doc flavors a
 454  * Java Print Service instance supports without having
 455  * to load the representation classes, which may be problematic for
 456  * limited-resource clients.
 457  *
 458  * @author  Alan Kaminsky
 459  */
 460 public class DocFlavor implements Serializable, Cloneable {
 461 
 462     private static final long serialVersionUID = -4512080796965449721L;
 463 
 464     /**
 465      * A String representing the host operating system encoding.
 466      * This will follow the conventions documented in
 467      * <a href="http://www.ietf.org/rfc/rfc2278.txt">
 468      * <i>RFC&nbsp;2278:&nbsp;IANA Charset Registration Procedures</i></a>
 469      * except where historical names are returned for compatibility with
 470      * previous versions of the Java platform.
 471      * The value returned from method is valid only for the VM which
 472      * returns it, for use in a DocFlavor.
 473      * This is the charset for all the "HOST" pre-defined DocFlavors in
 474      * the executing VM.
 475      */
 476     public static final String hostEncoding;
 477 
 478     static {
 479         hostEncoding =
 480             java.security.AccessController.doPrivileged(
 481                   new sun.security.action.GetPropertyAction("file.encoding"));
 482     }
 483 
 484     /**
 485      * MIME type.
 486      */
 487     private transient MimeType myMimeType;
 488 
 489     /**
 490      * Representation class name.
 491      * @serial
 492      */
 493     private String myClassName;
 494 
 495     /**
 496      * String value for this doc flavor. Computed when needed and cached.
 497      */
 498     private transient String myStringValue = null;
 499 
 500 
 501     /**
 502      * Constructs a new doc flavor object from the given MIME type and
 503      * representation class name. The given MIME type is converted into
 504      * canonical form and stored internally.
 505      *
 506      * @param  mimeType   MIME media type string.
 507      * @param  className  Fully-qualified representation class name.
 508      *
 509      * @exception  NullPointerException
 510      *     (unchecked exception) Thrown if {@code mimeType} is null or
 511      *     {@code className} is null.
 512      * @exception  IllegalArgumentException
 513      *     (unchecked exception) Thrown if {@code mimeType} does not
 514      *     obey the syntax for a MIME media type string.
 515      */
 516     public DocFlavor(String mimeType, String className) {
 517         if (className == null) {
 518             throw new NullPointerException();
 519         }
 520         myMimeType = new MimeType (mimeType);
 521         myClassName = className;
 522     }
 523 
 524     /**
 525      * Returns this doc flavor object's MIME type string based on the
 526      * canonical form. Each parameter value is enclosed in quotes.
 527      * @return the mime type
 528      */
 529     public String getMimeType() {
 530         return myMimeType.getMimeType();
 531     }
 532 
 533     /**
 534      * Returns this doc flavor object's media type (from the MIME type).
 535      * @return the media type
 536      */
 537     public String getMediaType() {
 538         return myMimeType.getMediaType();
 539     }
 540 
 541     /**
 542      * Returns this doc flavor object's media subtype (from the MIME type).
 543      * @return the media sub-type
 544      */
 545     public String getMediaSubtype() {
 546         return myMimeType.getMediaSubtype();
 547     }
 548 
 549     /**
 550      * Returns a {@code String} representing a MIME
 551      * parameter.
 552      * Mime types may include parameters which are usually optional.
 553      * The charset for text types is a commonly useful example.
 554      * This convenience method will return the value of the specified
 555      * parameter if one was specified in the mime type for this flavor.
 556      *
 557      * @param paramName the name of the paramater. This name is internally
 558      * converted to the canonical lower case format before performing
 559      * the match.
 560      * @return String representing a mime parameter, or
 561      * null if that parameter is not in the mime type string.
 562      * @exception NullPointerException if paramName is null.
 563      */
 564     public String getParameter(String paramName) {
 565         return myMimeType.getParameterMap().get(paramName.toLowerCase());
 566     }
 567 
 568     /**
 569      * Returns the name of this doc flavor object's representation class.
 570      * @return the name of the representation class.
 571      */
 572     public String getRepresentationClassName() {
 573         return myClassName;
 574     }
 575 
 576     /**
 577      * Converts this {@code DocFlavor} to a string.
 578      *
 579      * @return  MIME type string based on the canonical form. Each parameter
 580      *          value is enclosed in quotes.
 581      *          A "class=" parameter is appended to the
 582      *          MIME type string to indicate the representation class name.
 583      */
 584     public String toString() {
 585         return getStringValue();
 586     }
 587 
 588     /**
 589      * Returns a hash code for this doc flavor object.
 590      */
 591     public int hashCode() {
 592         return getStringValue().hashCode();
 593     }
 594 
 595     /**
 596      * Determines if this doc flavor object is equal to the given object.
 597      * The two are equal if the given object is not null, is an instance
 598      * of {@code DocFlavor}, has a MIME type equivalent to this doc
 599      * flavor object's MIME type (that is, the MIME types have the same media
 600      * type, media subtype, and parameters), and has the same representation
 601      * class name as this doc flavor object. Thus, if two doc flavor objects'
 602      * MIME types are the same except for comments, they are considered equal.
 603      * However, two doc flavor objects with MIME types of "text/plain" and
 604      * "text/plain; charset=US-ASCII" are not considered equal, even though
 605      * they represent the same media type (because the default character
 606      * set for plain text is US-ASCII).
 607      *
 608      * @param  obj  Object to test.
 609      *
 610      * @return  True if this doc flavor object equals {@code obj}, false
 611      *          otherwise.
 612      */
 613     public boolean equals(Object obj) {
 614         return
 615             obj != null &&
 616             obj instanceof DocFlavor &&
 617             getStringValue().equals (((DocFlavor) obj).getStringValue());
 618     }
 619 
 620     /**
 621      * Returns this doc flavor object's string value.
 622      */
 623     private String getStringValue() {
 624         if (myStringValue == null) {
 625             myStringValue = myMimeType + "; class=\"" + myClassName + "\"";
 626         }
 627         return myStringValue;
 628     }
 629 
 630     /**
 631      * Write the instance to a stream (ie serialize the object).
 632      *
 633      * @throws IOException if I/O errors occur while writing to the underlying
 634      * stream
 635      */
 636     private void writeObject(ObjectOutputStream s) throws IOException {
 637 
 638         s.defaultWriteObject();
 639         s.writeObject(myMimeType.getMimeType());
 640     }
 641 
 642     /**
 643      * Reconstitute an instance from a stream (that is, deserialize it).
 644      *
 645      * @throws ClassNotFoundException if the class of a serialized object could
 646      * not be found.
 647      * @throws IOException if I/O errors occur while reading from the underlying
 648      * stream
 649      * @serialData
 650      * The serialised form of a DocFlavor is the String naming the
 651      * representation class followed by the String representing the canonical
 652      * form of the mime type.
 653      */
 654     private void readObject(ObjectInputStream s)
 655         throws ClassNotFoundException, IOException {
 656 
 657         s.defaultReadObject();
 658         myMimeType = new MimeType((String)s.readObject());
 659     }
 660 
 661     /**
 662      * Class DocFlavor.BYTE_ARRAY provides predefined static constant
 663      * DocFlavor objects for example doc flavors using a byte array
 664      * ({@code byte[]}) as the print data representation class.
 665      *
 666      * @author  Alan Kaminsky
 667      */
 668     public static class BYTE_ARRAY extends DocFlavor {
 669 
 670         private static final long serialVersionUID = -9065578006593857475L;
 671 
 672         /**
 673          * Constructs a new doc flavor with the given MIME type and a print
 674          * data representation class name of {@code "[B"} (byte array).
 675          *
 676          * @param  mimeType   MIME media type string.
 677          *
 678          * @exception  NullPointerException
 679          *     (unchecked exception) Thrown if {@code mimeType} is null.
 680          * @exception  IllegalArgumentException
 681          *     (unchecked exception) Thrown if {@code mimeType} does not
 682          *     obey the syntax for a MIME media type string.
 683          */
 684         public BYTE_ARRAY (String mimeType) {
 685             super (mimeType, "[B");
 686         }
 687 
 688         /**
 689          * Doc flavor with MIME type = {@code "text/plain"},
 690          * encoded in the host platform encoding.
 691          * See {@link DocFlavor#hostEncoding hostEncoding}
 692          * Print data representation class name =
 693          * {@code "[B"} (byte array).
 694          */
 695         public static final BYTE_ARRAY TEXT_PLAIN_HOST =
 696             new BYTE_ARRAY ("text/plain; charset="+hostEncoding);
 697 
 698         /**
 699          * Doc flavor with MIME type =
 700          * {@code "text/plain; charset=utf-8"},
 701          * print data representation class name = {@code "[B"} (byte
 702          * array).
 703          */
 704         public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 =
 705             new BYTE_ARRAY ("text/plain; charset=utf-8");
 706 
 707         /**
 708          * Doc flavor with MIME type =
 709          * {@code "text/plain; charset=utf-16"},
 710          * print data representation class name = {@code "[B"} (byte
 711          * array).
 712          */
 713         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 =
 714             new BYTE_ARRAY ("text/plain; charset=utf-16");
 715 
 716 
 717         /**
 718          * Doc flavor with MIME type =
 719          * {@code "text/plain; charset=utf-16be"}
 720          * (big-endian byte ordering),
 721          * print data representation class name = {@code "[B"} (byte
 722          * array).
 723          */
 724         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE =
 725             new BYTE_ARRAY ("text/plain; charset=utf-16be");
 726 
 727         /**
 728          * Doc flavor with MIME type =
 729          * {@code "text/plain; charset=utf-16le"}
 730          * (little-endian byte ordering),
 731          * print data representation class name = {@code "[B"} (byte
 732          * array).
 733          */
 734         public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE =
 735             new BYTE_ARRAY ("text/plain; charset=utf-16le");
 736 
 737         /**
 738          * Doc flavor with MIME type =
 739          * {@code "text/plain; charset=us-ascii"},
 740          * print data representation class name =
 741          * {@code "[B"} (byte array).
 742          */
 743         public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII =
 744             new BYTE_ARRAY ("text/plain; charset=us-ascii");
 745 
 746 
 747         /**
 748          * Doc flavor with MIME type = {@code "text/html"},
 749          * encoded in the host platform encoding.
 750          * See {@link DocFlavor#hostEncoding hostEncoding}
 751          * Print data representation class name =
 752          * {@code "[B"} (byte array).
 753          */
 754         public static final BYTE_ARRAY TEXT_HTML_HOST =
 755             new BYTE_ARRAY ("text/html; charset="+hostEncoding);
 756 
 757         /**
 758          * Doc flavor with MIME type =
 759          * {@code "text/html; charset=utf-8"},
 760          * print data representation class name = {@code "[B"} (byte
 761          * array).
 762          */
 763         public static final BYTE_ARRAY TEXT_HTML_UTF_8 =
 764             new BYTE_ARRAY ("text/html; charset=utf-8");
 765 
 766         /**
 767          * Doc flavor with MIME type =
 768          * {@code "text/html; charset=utf-16"},
 769          * print data representation class name = {@code "[B"} (byte
 770          * array).
 771          */
 772         public static final BYTE_ARRAY TEXT_HTML_UTF_16 =
 773             new BYTE_ARRAY ("text/html; charset=utf-16");
 774 
 775         /**
 776          * Doc flavor with MIME type =
 777          * {@code "text/html; charset=utf-16be"}
 778          * (big-endian byte ordering),
 779          * print data representation class name = {@code "[B"} (byte
 780          * array).
 781          */
 782         public static final BYTE_ARRAY TEXT_HTML_UTF_16BE =
 783             new BYTE_ARRAY ("text/html; charset=utf-16be");
 784 
 785         /**
 786          * Doc flavor with MIME type =
 787          * {@code "text/html; charset=utf-16le"}
 788          * (little-endian byte ordering),
 789          * print data representation class name = {@code "[B"} (byte
 790          * array).
 791          */
 792         public static final BYTE_ARRAY TEXT_HTML_UTF_16LE =
 793             new BYTE_ARRAY ("text/html; charset=utf-16le");
 794 
 795         /**
 796          * Doc flavor with MIME type =
 797          * {@code "text/html; charset=us-ascii"},
 798          * print data representation class name =
 799          * {@code "[B"} (byte array).
 800          */
 801         public static final BYTE_ARRAY TEXT_HTML_US_ASCII =
 802             new BYTE_ARRAY ("text/html; charset=us-ascii");
 803 
 804 
 805         /**
 806          * Doc flavor with MIME type = {@code "application/pdf"}, print
 807          * data representation class name = {@code "[B"} (byte array).
 808          */
 809         public static final BYTE_ARRAY PDF = new BYTE_ARRAY ("application/pdf");
 810 
 811         /**
 812          * Doc flavor with MIME type = {@code "application/postscript"},
 813          * print data representation class name = {@code "[B"} (byte
 814          * array).
 815          */
 816         public static final BYTE_ARRAY POSTSCRIPT =
 817             new BYTE_ARRAY ("application/postscript");
 818 
 819         /**
 820          * Doc flavor with MIME type = {@code "application/vnd.hp-PCL"},
 821          * print data representation class name = {@code "[B"} (byte
 822          * array).
 823          */
 824         public static final BYTE_ARRAY PCL =
 825             new BYTE_ARRAY ("application/vnd.hp-PCL");
 826 
 827         /**
 828          * Doc flavor with MIME type = {@code "image/gif"}, print data
 829          * representation class name = {@code "[B"} (byte array).
 830          */
 831         public static final BYTE_ARRAY GIF = new BYTE_ARRAY ("image/gif");
 832 
 833         /**
 834          * Doc flavor with MIME type = {@code "image/jpeg"}, print data
 835          * representation class name = {@code "[B"} (byte array).
 836          */
 837         public static final BYTE_ARRAY JPEG = new BYTE_ARRAY ("image/jpeg");
 838 
 839         /**
 840          * Doc flavor with MIME type = {@code "image/png"}, print data
 841          * representation class name = {@code "[B"} (byte array).
 842          */
 843         public static final BYTE_ARRAY PNG = new BYTE_ARRAY ("image/png");
 844 
 845         /**
 846          * Doc flavor with MIME type =
 847          * {@code "application/octet-stream"},
 848          * print data representation class name = {@code "[B"} (byte
 849          * array). The client must determine that data described
 850          * using this DocFlavor is valid for the printer.
 851          */
 852         public static final BYTE_ARRAY AUTOSENSE =
 853             new BYTE_ARRAY ("application/octet-stream");
 854 
 855     }
 856 
 857     /**
 858      * Class DocFlavor.INPUT_STREAM provides predefined static constant
 859      * DocFlavor objects for example doc flavors using a byte stream ({@link
 860      * java.io.InputStream java.io.InputStream}) as the print
 861      * data representation class.
 862      *
 863      * @author  Alan Kaminsky
 864      */
 865     public static class INPUT_STREAM extends DocFlavor {
 866 
 867         private static final long serialVersionUID = -7045842700749194127L;
 868 
 869         /**
 870          * Constructs a new doc flavor with the given MIME type and a print
 871          * data representation class name of
 872          * {@code "java.io.InputStream"} (byte stream).
 873          *
 874          * @param  mimeType   MIME media type string.
 875          *
 876          * @exception  NullPointerException
 877          *     (unchecked exception) Thrown if {@code mimeType} is null.
 878          * @exception  IllegalArgumentException
 879          *     (unchecked exception) Thrown if {@code mimeType} does not
 880          *     obey the syntax for a MIME media type string.
 881          */
 882         public INPUT_STREAM (String mimeType) {
 883             super (mimeType, "java.io.InputStream");
 884         }
 885 
 886         /**
 887          * Doc flavor with MIME type = {@code "text/plain"},
 888          * encoded in the host platform encoding.
 889          * See {@link DocFlavor#hostEncoding hostEncoding}
 890          * Print data representation class name =
 891          * {@code "java.io.InputStream"} (byte stream).
 892          */
 893         public static final INPUT_STREAM TEXT_PLAIN_HOST =
 894             new INPUT_STREAM ("text/plain; charset="+hostEncoding);
 895 
 896         /**
 897          * Doc flavor with MIME type =
 898          * {@code "text/plain; charset=utf-8"},
 899          * print data representation class name =
 900          * {@code "java.io.InputStream"} (byte stream).
 901          */
 902         public static final INPUT_STREAM TEXT_PLAIN_UTF_8 =
 903             new INPUT_STREAM ("text/plain; charset=utf-8");
 904 
 905         /**
 906          * Doc flavor with MIME type =
 907          * {@code "text/plain; charset=utf-16"},
 908          * print data representation class name =
 909          * {@code "java.io.InputStream"} (byte stream).
 910          */
 911         public static final INPUT_STREAM TEXT_PLAIN_UTF_16 =
 912             new INPUT_STREAM ("text/plain; charset=utf-16");
 913 
 914         /**
 915          * Doc flavor with MIME type =
 916          * {@code "text/plain; charset=utf-16be"}
 917          * (big-endian byte ordering),
 918          * print data representation class name =
 919          * {@code "java.io.InputStream"} (byte stream).
 920          */
 921         public static final INPUT_STREAM TEXT_PLAIN_UTF_16BE =
 922             new INPUT_STREAM ("text/plain; charset=utf-16be");
 923 
 924         /**
 925          * Doc flavor with MIME type =
 926          * {@code "text/plain; charset=utf-16le"}
 927          * (little-endian byte ordering),
 928          * print data representation class name =
 929          * {@code "java.io.InputStream"} (byte stream).
 930          */
 931         public static final INPUT_STREAM TEXT_PLAIN_UTF_16LE =
 932             new INPUT_STREAM ("text/plain; charset=utf-16le");
 933 
 934         /**
 935          * Doc flavor with MIME type =
 936          * {@code "text/plain; charset=us-ascii"},
 937          * print data representation class name =
 938          * {@code "java.io.InputStream"} (byte stream).
 939          */
 940         public static final INPUT_STREAM TEXT_PLAIN_US_ASCII =
 941                 new INPUT_STREAM ("text/plain; charset=us-ascii");
 942 
 943         /**
 944          * Doc flavor with MIME type = {@code "text/html"},
 945          * encoded in the host platform encoding.
 946          * See {@link DocFlavor#hostEncoding hostEncoding}
 947          * Print data representation class name =
 948          * {@code "java.io.InputStream"} (byte stream).
 949          */
 950         public static final INPUT_STREAM TEXT_HTML_HOST =
 951             new INPUT_STREAM ("text/html; charset="+hostEncoding);
 952 
 953         /**
 954          * Doc flavor with MIME type =
 955          * {@code "text/html; charset=utf-8"},
 956          * print data representation class name =
 957          * {@code "java.io.InputStream"} (byte stream).
 958          */
 959         public static final INPUT_STREAM TEXT_HTML_UTF_8 =
 960             new INPUT_STREAM ("text/html; charset=utf-8");
 961 
 962         /**
 963          * Doc flavor with MIME type =
 964          * {@code "text/html; charset=utf-16"},
 965          * print data representation class name =
 966          * {@code "java.io.InputStream"} (byte stream).
 967          */
 968         public static final INPUT_STREAM TEXT_HTML_UTF_16 =
 969             new INPUT_STREAM ("text/html; charset=utf-16");
 970 
 971         /**
 972          * Doc flavor with MIME type =
 973          * {@code "text/html; charset=utf-16be"}
 974          * (big-endian byte ordering),
 975          * print data representation class name =
 976          * {@code "java.io.InputStream"} (byte stream).
 977          */
 978         public static final INPUT_STREAM TEXT_HTML_UTF_16BE =
 979             new INPUT_STREAM ("text/html; charset=utf-16be");
 980 
 981         /**
 982          * Doc flavor with MIME type =
 983          * {@code "text/html; charset=utf-16le"}
 984          * (little-endian byte ordering),
 985          * print data representation class name =
 986          * {@code "java.io.InputStream"} (byte stream).
 987          */
 988         public static final INPUT_STREAM TEXT_HTML_UTF_16LE =
 989             new INPUT_STREAM ("text/html; charset=utf-16le");
 990 
 991         /**
 992          * Doc flavor with MIME type =
 993          * {@code "text/html; charset=us-ascii"},
 994          * print data representation class name =
 995          * {@code "java.io.InputStream"} (byte stream).
 996          */
 997         public static final INPUT_STREAM TEXT_HTML_US_ASCII =
 998             new INPUT_STREAM ("text/html; charset=us-ascii");
 999 
1000 
1001         /**
1002          * Doc flavor with MIME type = {@code "application/pdf"}, print
1003          * data representation class name = {@code "java.io.InputStream"}
1004          * (byte stream).
1005          */
1006         public static final INPUT_STREAM PDF = new INPUT_STREAM ("application/pdf");
1007 
1008         /**
1009          * Doc flavor with MIME type = {@code "application/postscript"},
1010          * print data representation class name =
1011          * {@code "java.io.InputStream"} (byte stream).
1012          */
1013         public static final INPUT_STREAM POSTSCRIPT =
1014             new INPUT_STREAM ("application/postscript");
1015 
1016         /**
1017          * Doc flavor with MIME type = {@code "application/vnd.hp-PCL"},
1018          * print data representation class name =
1019          * {@code "java.io.InputStream"} (byte stream).
1020          */
1021         public static final INPUT_STREAM PCL =
1022             new INPUT_STREAM ("application/vnd.hp-PCL");
1023 
1024         /**
1025          * Doc flavor with MIME type = {@code "image/gif"}, print data
1026          * representation class name =
1027          * {@code "java.io.InputStream"} (byte stream).
1028          */
1029         public static final INPUT_STREAM GIF = new INPUT_STREAM ("image/gif");
1030 
1031         /**
1032          * Doc flavor with MIME type = {@code "image/jpeg"}, print data
1033          * representation class name =
1034          * {@code "java.io.InputStream"} (byte stream).
1035          */
1036         public static final INPUT_STREAM JPEG = new INPUT_STREAM ("image/jpeg");
1037 
1038         /**
1039          * Doc flavor with MIME type = {@code "image/png"}, print data
1040          * representation class name =
1041          * {@code "java.io.InputStream"} (byte stream).
1042          */
1043         public static final INPUT_STREAM PNG = new INPUT_STREAM ("image/png");
1044 
1045         /**
1046          * Doc flavor with MIME type =
1047          * {@code "application/octet-stream"},
1048          * print data representation class name =
1049          * {@code "java.io.InputStream"} (byte stream).
1050          * The client must determine that data described
1051          * using this DocFlavor is valid for the printer.
1052          */
1053         public static final INPUT_STREAM AUTOSENSE =
1054             new INPUT_STREAM ("application/octet-stream");
1055 
1056     }
1057 
1058     /**
1059      * Class DocFlavor.URL provides predefined static constant DocFlavor
1060      * objects.
1061      * For example doc flavors using a Uniform Resource Locator ({@link
1062      * java.net.URL java.net.URL}) as the print data
1063      * representation class.
1064      *
1065      * @author  Alan Kaminsky
1066      */
1067     public static class URL extends DocFlavor {
1068         private static final long serialVersionUID = 2936725788144902062L;
1069 
1070         /**
1071          * Constructs a new doc flavor with the given MIME type and a print
1072          * data representation class name of {@code "java.net.URL"}.
1073          *
1074          * @param  mimeType   MIME media type string.
1075          *
1076          * @exception  NullPointerException
1077          *     (unchecked exception) Thrown if {@code mimeType} is null.
1078          * @exception  IllegalArgumentException
1079          *     (unchecked exception) Thrown if {@code mimeType} does not
1080          *     obey the syntax for a MIME media type string.
1081          */
1082         public URL (String mimeType) {
1083             super (mimeType, "java.net.URL");
1084         }
1085 
1086         /**
1087          * Doc flavor with MIME type = {@code "text/plain"},
1088          * encoded in the host platform encoding.
1089          * See {@link DocFlavor#hostEncoding hostEncoding}
1090          * Print data representation class name =
1091          * {@code "java.net.URL"} (byte stream).
1092          */
1093         public static final URL TEXT_PLAIN_HOST =
1094             new URL ("text/plain; charset="+hostEncoding);
1095 
1096         /**
1097          * Doc flavor with MIME type =
1098          * {@code "text/plain; charset=utf-8"},
1099          * print data representation class name =
1100          * {@code "java.net.URL"} (byte stream).
1101          */
1102         public static final URL TEXT_PLAIN_UTF_8 =
1103             new URL ("text/plain; charset=utf-8");
1104 
1105         /**
1106          * Doc flavor with MIME type =
1107          * {@code "text/plain; charset=utf-16"},
1108          * print data representation class name =
1109          * {@code java.net.URL""} (byte stream).
1110          */
1111         public static final URL TEXT_PLAIN_UTF_16 =
1112             new URL ("text/plain; charset=utf-16");
1113 
1114         /**
1115          * Doc flavor with MIME type =
1116          * {@code "text/plain; charset=utf-16be"}
1117          * (big-endian byte ordering),
1118          * print data representation class name =
1119          * {@code "java.net.URL"} (byte stream).
1120          */
1121         public static final URL TEXT_PLAIN_UTF_16BE =
1122             new URL ("text/plain; charset=utf-16be");
1123 
1124         /**
1125          * Doc flavor with MIME type =
1126          * {@code "text/plain; charset=utf-16le"}
1127          * (little-endian byte ordering),
1128          * print data representation class name =
1129          * {@code "java.net.URL"} (byte stream).
1130          */
1131         public static final URL TEXT_PLAIN_UTF_16LE =
1132             new URL ("text/plain; charset=utf-16le");
1133 
1134         /**
1135          * Doc flavor with MIME type =
1136          * {@code "text/plain; charset=us-ascii"},
1137          * print data representation class name =
1138          * {@code "java.net.URL"} (byte stream).
1139          */
1140         public static final URL TEXT_PLAIN_US_ASCII =
1141             new URL ("text/plain; charset=us-ascii");
1142 
1143         /**
1144          * Doc flavor with MIME type = {@code "text/html"},
1145          * encoded in the host platform encoding.
1146          * See {@link DocFlavor#hostEncoding hostEncoding}
1147          * Print data representation class name =
1148          * {@code "java.net.URL"} (byte stream).
1149          */
1150         public static final URL TEXT_HTML_HOST =
1151             new URL ("text/html; charset="+hostEncoding);
1152 
1153         /**
1154          * Doc flavor with MIME type =
1155          * {@code "text/html; charset=utf-8"},
1156          * print data representation class name =
1157          * {@code "java.net.URL"} (byte stream).
1158          */
1159         public static final URL TEXT_HTML_UTF_8 =
1160             new URL ("text/html; charset=utf-8");
1161 
1162         /**
1163          * Doc flavor with MIME type =
1164          * {@code "text/html; charset=utf-16"},
1165          * print data representation class name =
1166          * {@code "java.net.URL"} (byte stream).
1167          */
1168         public static final URL TEXT_HTML_UTF_16 =
1169             new URL ("text/html; charset=utf-16");
1170 
1171         /**
1172          * Doc flavor with MIME type =
1173          * {@code "text/html; charset=utf-16be"}
1174          * (big-endian byte ordering),
1175          * print data representation class name =
1176          * {@code "java.net.URL"} (byte stream).
1177          */
1178         public static final URL TEXT_HTML_UTF_16BE =
1179             new URL ("text/html; charset=utf-16be");
1180 
1181         /**
1182          * Doc flavor with MIME type =
1183          * {@code "text/html; charset=utf-16le"}
1184          * (little-endian byte ordering),
1185          * print data representation class name =
1186          * {@code "java.net.URL"} (byte stream).
1187          */
1188         public static final URL TEXT_HTML_UTF_16LE =
1189             new URL ("text/html; charset=utf-16le");
1190 
1191         /**
1192          * Doc flavor with MIME type =
1193          * {@code "text/html; charset=us-ascii"},
1194          * print data representation class name =
1195          * {@code "java.net.URL"} (byte stream).
1196          */
1197         public static final URL TEXT_HTML_US_ASCII =
1198             new URL ("text/html; charset=us-ascii");
1199 
1200 
1201         /**
1202          * Doc flavor with MIME type = {@code "application/pdf"}, print
1203          * data representation class name = {@code "java.net.URL"}.
1204          */
1205         public static final URL PDF = new URL ("application/pdf");
1206 
1207         /**
1208          * Doc flavor with MIME type = {@code "application/postscript"},
1209          * print data representation class name = {@code "java.net.URL"}.
1210          */
1211         public static final URL POSTSCRIPT = new URL ("application/postscript");
1212 
1213         /**
1214          * Doc flavor with MIME type = {@code "application/vnd.hp-PCL"},
1215          * print data representation class name = {@code "java.net.URL"}.
1216          */
1217         public static final URL PCL = new URL ("application/vnd.hp-PCL");
1218 
1219         /**
1220          * Doc flavor with MIME type = {@code "image/gif"}, print data
1221          * representation class name = {@code "java.net.URL"}.
1222          */
1223         public static final URL GIF = new URL ("image/gif");
1224 
1225         /**
1226          * Doc flavor with MIME type = {@code "image/jpeg"}, print data
1227          * representation class name = {@code "java.net.URL"}.
1228          */
1229         public static final URL JPEG = new URL ("image/jpeg");
1230 
1231         /**
1232          * Doc flavor with MIME type = {@code "image/png"}, print data
1233          * representation class name = {@code "java.net.URL"}.
1234          */
1235         public static final URL PNG = new URL ("image/png");
1236 
1237         /**
1238          * Doc flavor with MIME type =
1239          * {@code "application/octet-stream"},
1240          * print data representation class name = {@code "java.net.URL"}.
1241          *  The client must determine that data described
1242          * using this DocFlavor is valid for the printer.
1243          */
1244         public static final URL AUTOSENSE = new URL ("application/octet-stream");
1245 
1246     }
1247 
1248     /**
1249      * Class DocFlavor.CHAR_ARRAY provides predefined static constant
1250      * DocFlavor objects for example doc flavors using a character array
1251      * ({@code char[]}) as the print data representation class. As such,
1252      * the character set is Unicode.
1253      *
1254      * @author  Alan Kaminsky
1255      */
1256     public static class CHAR_ARRAY extends DocFlavor {
1257 
1258         private static final long serialVersionUID = -8720590903724405128L;
1259 
1260         /**
1261          * Constructs a new doc flavor with the given MIME type and a print
1262          * data representation class name of
1263          * {@code "[C"} (character array).
1264          *
1265          * @param  mimeType  MIME media type string. If it is a text media
1266          *                      type, it is assumed to contain a
1267          *                      {@code "charset=utf-16"} parameter.
1268          *
1269          * @exception  NullPointerException
1270          *     (unchecked exception) Thrown if {@code mimeType} is null.
1271          * @exception  IllegalArgumentException
1272          *     (unchecked exception) Thrown if {@code mimeType} does not
1273          *     obey the syntax for a MIME media type string.
1274          */
1275         public CHAR_ARRAY (String mimeType) {
1276             super (mimeType, "[C");
1277         }
1278 
1279         /**
1280          * Doc flavor with MIME type = {@code "text/plain; charset=utf-16"},
1281          * print data representation class name =
1282          * {@code "[C"} (character array).
1283          */
1284         public static final CHAR_ARRAY TEXT_PLAIN =
1285             new CHAR_ARRAY ("text/plain; charset=utf-16");
1286 
1287         /**
1288          * Doc flavor with MIME type = {@code "text/html; charset=utf-16"},
1289          * print data representation class name =
1290          * {@code "[C"} (character array).
1291          */
1292         public static final CHAR_ARRAY TEXT_HTML =
1293             new CHAR_ARRAY ("text/html; charset=utf-16");
1294 
1295     }
1296 
1297     /**
1298      * Class DocFlavor.STRING provides predefined static constant DocFlavor
1299      * objects for example doc flavors using a string ({@link java.lang.String
1300      * java.lang.String}) as the print data representation class.
1301      * As such, the character set is Unicode.
1302      *
1303      * @author  Alan Kaminsky
1304      */
1305     public static class STRING extends DocFlavor {
1306 
1307         private static final long serialVersionUID = 4414407504887034035L;
1308 
1309         /**
1310          * Constructs a new doc flavor with the given MIME type and a print
1311          * data representation class name of {@code "java.lang.String"}.
1312          *
1313          * @param  mimeType  MIME media type string. If it is a text media
1314          *                      type, it is assumed to contain a
1315          *                      {@code "charset=utf-16"} parameter.
1316          *
1317          * @exception  NullPointerException
1318          *     (unchecked exception) Thrown if {@code mimeType} is null.
1319          * @exception  IllegalArgumentException
1320          *     (unchecked exception) Thrown if {@code mimeType} does not
1321          *     obey the syntax for a MIME media type string.
1322          */
1323         public STRING (String mimeType) {
1324             super (mimeType, "java.lang.String");
1325         }
1326 
1327         /**
1328          * Doc flavor with MIME type = {@code "text/plain; charset=utf-16"},
1329          * print data representation class name =
1330          * {@code "java.lang.String"}.
1331          */
1332         public static final STRING TEXT_PLAIN =
1333             new STRING ("text/plain; charset=utf-16");
1334 
1335         /**
1336          * Doc flavor with MIME type = {@code "text/html; charset=utf-16"},
1337          * print data representation class name =
1338          * {@code "java.lang.String"}.
1339          */
1340         public static final STRING TEXT_HTML =
1341             new STRING ("text/html; charset=utf-16");
1342     }
1343 
1344     /**
1345      * Class DocFlavor.READER provides predefined static constant DocFlavor
1346      * objects for example doc flavors using a character stream ({@link
1347      * java.io.Reader java.io.Reader}) as the print data
1348      * representation class. As such, the character set is Unicode.
1349      *
1350      * @author  Alan Kaminsky
1351      */
1352     public static class READER extends DocFlavor {
1353 
1354         private static final long serialVersionUID = 7100295812579351567L;
1355 
1356         /**
1357          * Constructs a new doc flavor with the given MIME type and a print
1358          * data representation class name of\
1359          * {@code "java.io.Reader"} (character stream).
1360          *
1361          * @param  mimeType  MIME media type string. If it is a text media
1362          *                      type, it is assumed to contain a
1363          *                      {@code "charset=utf-16"} parameter.
1364          *
1365          * @exception  NullPointerException
1366          *     (unchecked exception) Thrown if {@code mimeType} is null.
1367          * @exception  IllegalArgumentException
1368          *     (unchecked exception) Thrown if {@code mimeType} does not
1369          *     obey the syntax for a MIME media type string.
1370          */
1371         public READER (String mimeType) {
1372             super (mimeType, "java.io.Reader");
1373         }
1374 
1375         /**
1376          * Doc flavor with MIME type = {@code "text/plain; charset=utf-16"},
1377          * print data representation class name =
1378          * {@code "java.io.Reader"} (character stream).
1379          */
1380         public static final READER TEXT_PLAIN =
1381             new READER ("text/plain; charset=utf-16");
1382 
1383         /**
1384          * Doc flavor with MIME type = {@code "text/html; charset=utf-16"},
1385          * print data representation class name =
1386          * {@code "java.io.Reader"} (character stream).
1387          */
1388         public static final READER TEXT_HTML =
1389             new READER ("text/html; charset=utf-16");
1390 
1391     }
1392 
1393     /**
1394      * Class DocFlavor.SERVICE_FORMATTED provides predefined static constant
1395      * DocFlavor objects for example doc flavors for service formatted print
1396      * data.
1397      *
1398      * @author  Alan Kaminsky
1399      */
1400     public static class SERVICE_FORMATTED extends DocFlavor {
1401 
1402         private static final long serialVersionUID = 6181337766266637256L;
1403 
1404         /**
1405          * Constructs a new doc flavor with a MIME type of
1406          * {@code "application/x-java-jvm-local-objectref"} indicating
1407          * service formatted print data and the given print data
1408          * representation class name.
1409          *
1410          * @param  className  Fully-qualified representation class name.
1411          *
1412          * @exception  NullPointerException
1413          *     (unchecked exception) Thrown if {@code className} is
1414          *     null.
1415          */
1416         public SERVICE_FORMATTED (String className) {
1417             super ("application/x-java-jvm-local-objectref", className);
1418         }
1419 
1420         /**
1421          * Service formatted print data doc flavor with print data
1422          * representation class name =
1423          * {@code "java.awt.image.renderable.RenderableImage"}
1424          * (renderable image object).
1425          */
1426         public static final SERVICE_FORMATTED RENDERABLE_IMAGE =
1427             new SERVICE_FORMATTED("java.awt.image.renderable.RenderableImage");
1428 
1429         /**
1430          * Service formatted print data doc flavor with print data
1431          * representation class name = {@code "java.awt.print.Printable"}
1432          * (printable object).
1433          */
1434         public static final SERVICE_FORMATTED PRINTABLE =
1435             new SERVICE_FORMATTED ("java.awt.print.Printable");
1436 
1437         /**
1438          * Service formatted print data doc flavor with print data
1439          * representation class name = {@code "java.awt.print.Pageable"}
1440          * (pageable object).
1441          */
1442         public static final SERVICE_FORMATTED PAGEABLE =
1443             new SERVICE_FORMATTED ("java.awt.print.Pageable");
1444 
1445         }
1446 
1447 }