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