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