Path: blob/master/src/java.desktop/share/classes/javax/print/DocFlavor.java
41153 views
/*1* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.print;2627import java.io.IOException;28import java.io.ObjectInputStream;29import java.io.ObjectOutputStream;30import java.io.Serial;31import java.io.Serializable;3233/**34* Class {@code DocFlavor} encapsulates an object that specifies the format in35* 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 data37* format, or "doc flavor", consists of two things:38* <ul>39* <li><b>MIME type.</b> This is a Multipurpose Internet Mail Extensions40* (MIME) media type (as defined in41* <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a> and42* <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a>) that specifies43* how the print data is to be interpreted. The charset of text data should be44* the IANA MIME-preferred name, or its canonical name if no preferred name is45* specified. Additionally a few historical names supported by earlier46* versions of the Java platform may be recognized. See47* <a href="../../../java.base/java/lang/package-summary.html#charenc">48* character encodings</a> for more information on the character encodings49* supported on the Java platform.50* <li><b>Representation class name.</b> This specifies the fully-qualified51* name of the class of the object from which the actual print data comes, as52* returned by the {@link Class#getName() Class.getName()} method. (Thus the53* class name for {@code byte[]} is {@code "[B"}, for {@code char[]} it is54* {@code "[C"}.)55* </ul>56* A {@code DocPrintJob} obtains its print data by means of interface57* {@link Doc Doc}. A {@code Doc} object lets the {@code DocPrintJob} determine58* the doc flavor the client can supply. A {@code Doc} object also lets the59* {@code DocPrintJob} obtain an instance of the doc flavor's representation60* 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 and65* service formatted print data.66* <p>67* For <b>client formatted print data</b>, the client determines or knows the68* print data format. For example the client may have a JPEG encoded image, a69* {@code URL} for HTML code, or a disk file containing plain text in some70* encoding, possibly obtained from an external source, and requires a way to71* describe the data format to the print service.72* <p>73* The doc flavor's representation class is a conduit for the JPS74* {@code DocPrintJob} to obtain a sequence of characters or bytes from the75* client. The doc flavor's MIME type is one of the standard media types telling76* how to interpret the sequence of characters or bytes. For a list of standard77* media types, see the Internet Assigned Numbers Authority's (IANA's)78* <a href="http://www.iana.org/assignments/media-types/">Media Types Directory79* </a>. Interface {@link Doc Doc} provides two utility operations,80* {@link Doc#getReaderForText() getReaderForText} and81* {@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 is85* typically one of the following (although other representation classes are86* permitted):87* <ul>88* <li>Character array ({@code char[]}) -- The print data consists of the89* Unicode characters in the array.90* <li>{@code String} -- The print data consists of the Unicode characters in91* the string.92* <li>Character stream ({@link java.io.Reader java.io.Reader}) -- The print93* data consists of the Unicode characters read from the stream up to the94* end-of-stream.95* <li>Byte array ({@code byte[]}) -- The print data consists of the bytes in96* the array. The bytes are encoded in the character set specified by the doc97* flavor's MIME type. If the MIME type does not specify a character set, the98* default character set is US-ASCII.99* <li>Byte stream ({@link java.io.InputStream java.io.InputStream}) -- The100* print data consists of the bytes read from the stream up to the101* end-of-stream. The bytes are encoded in the character set specified by the102* 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 data105* consists of the bytes read from the URL location. The bytes are encoded in106* the character set specified by the doc flavor's MIME type. If the MIME type107* 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 itself109* accesses and downloads the document directly from its {@code URL} address,110* without involving the client. The service may be some form of network print111* service which is executing in a different environment. This means you112* should not use a {@code URL} print data flavor to print a document at a113* 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 print115* 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 not117* served up by an HTTP server or FTP server. To print such documents, let the118* client open an input stream on the {@code URL} or file and use an input119* 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 a125* {@code charset} parameter, the Java Print Service instance assumes the126* US-ASCII character set by default. This is in accordance with127* <a href="http://www.ietf.org/rfc/rfc2046.txt">RFC 2046</a>, which says the128* 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 the130* default in a compatible manner.131* <p>132* Also note that this is different than the behaviour of the Java runtime when133* interpreting a stream of bytes as text data. That assumes the default134* encoding for the user's locale. Thus, when spooling a file in local encoding135* to a Java Print Service it is important to correctly specify the encoding.136* Developers working in the English locales should be particularly conscious of137* this, as their platform encoding corresponds to the default mime charset. By138* this coincidence that particular case may work without specifying the139* encoding of platform data.140* <p>141* Every instance of the Java virtual machine has a default character encoding142* determined during virtual-machine startup and typically depends upon the143* locale and charset being used by the underlying operating system. In a144* distributed environment there is no guarantee that two VM share the same145* default encoding. Thus clients which want to stream platform encoded text146* data from the host platform to a Java Print Service instance must explicitly147* 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 the151* mime type, which necessitates obtaining the encoding of the host platform for152* data (eg files) stored in that platform's encoding. A {@code CharSet} which153* corresponds to this and is suitable for use in a mime-type for a154* {@code DocFlavor} can be obtained from155* {@link DocFlavor#hostEncoding DocFlavor.hostEncoding} This may not always be156* the primary IANA name but is guaranteed to be understood by this VM. For157* common flavors, the pre-defined *HOST {@code DocFlavors} may be used.158* <p>159* See <a href="../../../java.base/java/lang/package-summary.html#charenc">160* character encodings</a> for more information on the character encodings161* supported on the Java platform.162*163* <hr>164* <h2>Recommended DocFlavors</h2>165* The Java Print Service API does not define any mandatorily supported166* {@code DocFlavors}. However, here are some examples of MIME types that a Java167* Print Service instance might support for client formatted print data. Nested168* classes inside class {@code DocFlavor} declare predefined static constant169* {@code DocFlavor} objects for these example doc flavors; class170* {@code DocFlavor}'s constructor can be used to create an arbitrary doc171* flavor.172* <ul>173* <li>Preformatted text174* <table class="striped">175* <caption>MIME-Types and their descriptions</caption>176* <thead>177* <tr>178* <th scope="col">MIME-Type179* <th scope="col">Description180* </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 character197* oriented representation class (character array, String, Reader) or in a198* byte oriented representation class (byte array, InputStream, URL).199* <li>Preformatted page description language (PDL) documents200* <table class="striped">201* <caption>MIME-Types and their descriptions</caption>202* <thead>203* <tr>204* <th scope="col">MIME-Type205* <th scope="col">Description206* </thead>207* <tbody>208* <tr>209* <th scope="row">{@code "application/pdf"}210* <td>Portable Document Format document211* <tr>212* <th scope="row">{@code "application/postscript"}213* <td>PostScript document214* <tr>215* <th scope="row">{@code "application/vnd.hp-PCL"}216* <td>Printer Control Language document217* </tbody>218* </table>219* In general, preformatted PDL print data is provided in a byte oriented220* representation class (byte array, {@code InputStream}, {@code URL}).221* <li>Preformatted images222* <table class="striped">223* <caption>MIME-Types and their descriptions</caption>224* <thead>225* <tr>226* <th scope="col">MIME-Type227* <th scope="col">Description228* </thead>229* <tbody>230* <tr>231* <th scope="row">{@code "image/gif"}232* <td>Graphics Interchange Format image233* <tr>234* <th scope="row">{@code "image/jpeg"}235* <td>Joint Photographic Experts Group image236* <tr>237* <th scope="row">{@code "image/png"}238* <td>Portable Network Graphics image239* </tbody>240* </table>241* In general, preformatted image print data is provided in a byte oriented242* representation class (byte array, {@code InputStream}, {@code URL}).243* <li>Preformatted autosense print data244* <table class="striped">245* <caption>MIME-Types and their descriptions</caption>246* <thead>247* <tr>248* <th scope="col">MIME-Type249* <th scope="col">Description250* </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 this258* "autosensing" works is implementation dependent. In general, preformatted259* autosense print data is provided in a byte oriented representation class260* (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 instance266* determines the print data format. The doc flavor's representation class267* denotes an interface whose methods the {@code DocPrintJob} invokes to268* determine the content to be printed -- such as a renderable image interface269* or a Java printable interface. The doc flavor's MIME type is the special270* value {@code "application/x-java-jvm-local-objectref"} indicating the client271* will supply a reference to a Java object that implements the interface named272* as the representation class. This MIME type is just a placeholder; what's273* important is the print data representation class.274* <p>275* For service formatted print data, the print data representation class is276* typically one of the following (although other representation classes are277* permitted). Nested classes inside class {@code DocFlavor} declare predefined278* static constant {@code DocFlavor} objects for these example doc flavors;279* class {@code DocFlavor}'s constructor can be used to create an arbitrary doc280* flavor.281* <ul>282* <li>Renderable image object -- The client supplies an object that283* implements interface284* {@link java.awt.image.renderable.RenderableImage RenderableImage}. The285* printer calls methods in that interface to obtain the image to be printed.286* <li>Printable object -- The client supplies an object that implements287* interface {@link java.awt.print.Printable Printable}. The printer calls288* 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 the290* client draws in that graphics context gets printed.291* <li>Pageable object -- The client supplies an object that implements292* interface {@link java.awt.print.Pageable Pageable}. The printer calls293* 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 the295* 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 the301* following print data formats and print data representation classes. In fact,302* a developer using this class should <b>never</b> assume that a particular303* print service supports the document types corresponding to these pre-defined304* doc flavors. Always query the print service to determine what doc flavors it305* supports. However, developers who have print services that support these doc306* flavors are encouraged to refer to the predefined singleton instances created307* here.308* <ul>309* <li>Plain text print data provided through a byte stream. Specifically, the310* following doc flavors are recommended to be supported:311* <br>· 312* {@code ("text/plain", "java.io.InputStream")}313* <br>· 314* {@code ("text/plain; charset=us-ascii", "java.io.InputStream")}315* <br>· 316* {@code ("text/plain; charset=utf-8", "java.io.InputStream")}317* <li>Renderable image objects. Specifically, the following doc flavor is318* recommended to be supported:319* <br>· 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 (or323* none) in addition to the above mandatory ones, at the implementation's324* choice.325* <p>326* Support for the above doc flavors is desirable so a printing client can rely327* on being able to print on any JPS printer, regardless of which doc flavors328* the printer supports. If the printer doesn't support the client's preferred329* doc flavor, the client can at least print plain text, or the client can330* convert its data to a renderable image and print the image.331* <p>332* Furthermore, every Java Print Service instance must fulfill these333* requirements for processing plain text print data:334* <ul>335* <li>The character pair carriage return-line feed (CR-LF) means "go to336* column 1 of the next line."337* <li>A carriage return (CR) character standing by itself means "go to column338* 1 of the next line."339* <li>A line feed (LF) character standing by itself means "go to column 1 of340* the next line."341* </ul>342* The client must itself perform all plain text print data formatting not343* addressed by the above requirements.344*345* <h2>Design Rationale</h2>346* Class {@code DocFlavor} in package {@code javax.print} is similar to class347* {@link java.awt.datatransfer.DataFlavor}. Class {@code DataFlavor} is not348* used in the Java Print Service (JPS) API for three reasons which are all349* rooted in allowing the JPS API to be shared by other print services APIs350* which may need to run on Java profiles which do not include all of the Java351* Platform, Standard Edition.352* <ol type=1>353* <li>The JPS API is designed to be used in Java profiles which do not354* support AWT.355* <li>The implementation of class {@code java.awt.datatransfer.DataFlavor}356* does not guarantee that equivalent data flavors will have the same357* serialized representation. {@code DocFlavor} does, and can be used in358* 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 following364* canonical form of a MIME type string. Thus, two doc flavors with MIME types365* that are not identical but that are equivalent (that have the same canonical366* form) may be considered equal.367* <ul>368* <li>The media type, media subtype, and parameters are retained, but all369* comments and whitespace characters are discarded.370* <li>The media type, media subtype, and parameter names are converted to371* lowercase.372* <li>The parameter values retain their original case, except a charset373* 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 the379* fully-qualified class <i>name</i> of the representation class (a380* {@code String} object), rather than the representation class itself (a381* {@code Class} object). This allows a client to examine the doc flavors a Java382* Print Service instance supports without having to load the representation383* classes, which may be problematic for limited-resource clients.384*385* @author Alan Kaminsky386*/387@SuppressWarnings("removal")388public class DocFlavor implements Serializable, Cloneable {389390/**391* Use serialVersionUID from JDK 1.4 for interoperability.392*/393@Serial394private static final long serialVersionUID = -4512080796965449721L;395396/**397* A string representing the host operating system encoding. This will398* follow the conventions documented in399* <a href="http://www.ietf.org/rfc/rfc2278.txt">400* <i>RFC 2278: IANA Charset Registration Procedures</i></a>401* except where historical names are returned for compatibility with402* previous versions of the Java platform. The value returned from method is403* valid only for the VM which returns it, for use in a {@code DocFlavor}.404* This is the charset for all the "HOST" pre-defined {@code DocFlavors} in405* the executing VM.406*/407public static final String hostEncoding;408409static {410hostEncoding =411java.security.AccessController.doPrivileged(412new sun.security.action.GetPropertyAction("file.encoding"));413}414415/**416* MIME type.417*/418private transient MimeType myMimeType;419420/**421* Representation class name.422*423* @serial424*/425private String myClassName;426427/**428* String value for this doc flavor. Computed when needed and cached.429*/430private transient String myStringValue = null;431432/**433* Constructs a new doc flavor object from the given MIME type and434* representation class name. The given MIME type is converted into435* canonical form and stored internally.436*437* @param mimeType MIME media type string438* @param className fully-qualified representation class name439* @throws NullPointerException if {@code mimeType} or {@code className} is440* {@code null}441* @throws IllegalArgumentException if {@code mimeType} does not obey the442* syntax for a MIME media type string443*/444public DocFlavor(String mimeType, String className) {445if (className == null) {446throw new NullPointerException();447}448myMimeType = new MimeType (mimeType);449myClassName = className;450}451452/**453* Returns this doc flavor object's MIME type string based on the canonical454* form. Each parameter value is enclosed in quotes.455*456* @return the mime type457*/458public String getMimeType() {459return myMimeType.getMimeType();460}461462/**463* Returns this doc flavor object's media type (from the MIME type).464*465* @return the media type466*/467public String getMediaType() {468return myMimeType.getMediaType();469}470471/**472* Returns this doc flavor object's media subtype (from the MIME type).473*474* @return the media sub-type475*/476public String getMediaSubtype() {477return myMimeType.getMediaSubtype();478}479480/**481* Returns a {@code String} representing a MIME parameter. Mime types may482* include parameters which are usually optional. The charset for text types483* is a commonly useful example. This convenience method will return the484* value of the specified parameter if one was specified in the mime type485* for this flavor.486*487* @param paramName the name of the parameter. This name is internally488* converted to the canonical lower case format before performing489* the match.490* @return a string representing a mime parameter, or {@code null} if that491* parameter is not in the mime type string492* @throws NullPointerException if paramName is {@code null}493*/494public String getParameter(String paramName) {495return myMimeType.getParameterMap().get(paramName.toLowerCase());496}497498/**499* Returns the name of this doc flavor object's representation class.500*501* @return the name of the representation class502*/503public String getRepresentationClassName() {504return myClassName;505}506507/**508* Converts this {@code DocFlavor} to a string.509*510* @return MIME type string based on the canonical form. Each parameter511* value is enclosed in quotes. A "class=" parameter is appended to512* the MIME type string to indicate the representation class name.513*/514public String toString() {515return getStringValue();516}517518/**519* Returns a hash code for this doc flavor object.520*/521public int hashCode() {522return getStringValue().hashCode();523}524525/**526* Determines if this doc flavor object is equal to the given object. The527* two are equal if the given object is not {@code null}, is an instance of528* {@code DocFlavor}, has a MIME type equivalent to this doc flavor object's529* MIME type (that is, the MIME types have the same media type, media530* subtype, and parameters), and has the same representation class name as531* this doc flavor object. Thus, if two doc flavor objects' MIME types are532* the same except for comments, they are considered equal. However, two doc533* flavor objects with MIME types of "text/plain" and "text/plain;534* charset=US-ASCII" are not considered equal, even though they represent535* the same media type (because the default character set for plain text is536* US-ASCII).537*538* @param obj {@code Object} to test539* @return {@code true} if this doc flavor object equals {@code obj},540* {@code false} otherwise541*/542public boolean equals(Object obj) {543return544obj != null &&545obj instanceof DocFlavor &&546getStringValue().equals (((DocFlavor) obj).getStringValue());547}548549/**550* Returns this doc flavor object's string value.551*552* @return the string value553*/554private String getStringValue() {555if (myStringValue == null) {556myStringValue = myMimeType + "; class=\"" + myClassName + "\"";557}558return myStringValue;559}560561/**562* Write the instance to a stream (ie serialize the object).563*564* @param s the output stream565* @throws IOException if I/O errors occur while writing to the underlying566* stream567*/568@Serial569private void writeObject(ObjectOutputStream s) throws IOException {570571s.defaultWriteObject();572s.writeObject(myMimeType.getMimeType());573}574575/**576* Reconstitute an instance from a stream (that is, deserialize it).577*578* @param s the input stream579* @throws ClassNotFoundException if the class of a serialized object could580* not be found581* @throws IOException if I/O errors occur while reading from the underlying582* stream583* @serialData The serialised form of a {@code DocFlavor} is the584* {@code String} naming the representation class followed by585* the {@code String} representing the canonical form of the586* mime type587*/588@Serial589private void readObject(ObjectInputStream s)590throws ClassNotFoundException, IOException {591592s.defaultReadObject();593myMimeType = new MimeType((String)s.readObject());594}595596/**597* Class {@code DocFlavor.BYTE_ARRAY} provides predefined static constant598* {@code DocFlavor} objects for example doc flavors using a byte array599* ({@code byte[]}) as the print data representation class.600*601* @author Alan Kaminsky602*/603public static class BYTE_ARRAY extends DocFlavor {604605/**606* Use serialVersionUID from JDK 1.4 for interoperability.607*/608@Serial609private static final long serialVersionUID = -9065578006593857475L;610611/**612* Constructs a new doc flavor with the given MIME type and a print data613* representation class name of {@code "[B"} (byte array).614*615* @param mimeType MIME media type string616* @throws NullPointerException if {@code mimeType} is {@code null}617* @throws IllegalArgumentException if {@code mimeType} does not obey618* the syntax for a MIME media type string619*/620public BYTE_ARRAY (String mimeType) {621super (mimeType, "[B");622}623624/**625* Doc flavor with MIME type = {@code "text/plain"}, encoded in the host626* platform encoding. See {@link DocFlavor#hostEncoding hostEncoding}.627* Print data representation class name = {@code "[B"} (byte array).628*/629public static final BYTE_ARRAY TEXT_PLAIN_HOST =630new BYTE_ARRAY ("text/plain; charset="+hostEncoding);631632/**633* Doc flavor with MIME type = {@code "text/plain; charset=utf-8"},634* print data representation class name = {@code "[B"} (byte array).635*/636public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 =637new BYTE_ARRAY ("text/plain; charset=utf-8");638639/**640* Doc flavor with MIME type = {@code "text/plain; charset=utf-16"},641* print data representation class name = {@code "[B"} (byte array).642*/643public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 =644new BYTE_ARRAY ("text/plain; charset=utf-16");645646/**647* Doc flavor with MIME type = {@code "text/plain; charset=utf-16be"}648* (big-endian byte ordering), print data representation class name =649* {@code "[B"} (byte array).650*/651public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE =652new BYTE_ARRAY ("text/plain; charset=utf-16be");653654/**655* Doc flavor with MIME type = {@code "text/plain; charset=utf-16le"}656* (little-endian byte ordering), print data representation class name =657* {@code "[B"} (byte array).658*/659public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE =660new BYTE_ARRAY ("text/plain; charset=utf-16le");661662/**663* Doc flavor with MIME type = {@code "text/plain; charset=us-ascii"},664* print data representation class name = {@code "[B"} (byte array).665*/666public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII =667new BYTE_ARRAY ("text/plain; charset=us-ascii");668669670/**671* Doc flavor with MIME type = {@code "text/html"}, encoded in the host672* platform encoding. See {@link DocFlavor#hostEncoding hostEncoding}.673* Print data representation class name = {@code "[B"} (byte array).674*/675public static final BYTE_ARRAY TEXT_HTML_HOST =676new BYTE_ARRAY ("text/html; charset="+hostEncoding);677678/**679* Doc flavor with MIME type = {@code "text/html; charset=utf-8"}, print680* data representation class name = {@code "[B"} (byte array).681*/682public static final BYTE_ARRAY TEXT_HTML_UTF_8 =683new BYTE_ARRAY ("text/html; charset=utf-8");684685/**686* Doc flavor with MIME type = {@code "text/html; charset=utf-16"},687* print data representation class name = {@code "[B"} (byte array).688*/689public static final BYTE_ARRAY TEXT_HTML_UTF_16 =690new BYTE_ARRAY ("text/html; charset=utf-16");691692/**693* Doc flavor with MIME type = {@code "text/html; charset=utf-16be"}694* (big-endian byte ordering), print data representation class name =695* {@code "[B"} (byte array).696*/697public static final BYTE_ARRAY TEXT_HTML_UTF_16BE =698new BYTE_ARRAY ("text/html; charset=utf-16be");699700/**701* Doc flavor with MIME type = {@code "text/html; charset=utf-16le"}702* (little-endian byte ordering), print data representation class name =703* {@code "[B"} (byte array).704*/705public static final BYTE_ARRAY TEXT_HTML_UTF_16LE =706new BYTE_ARRAY ("text/html; charset=utf-16le");707708/**709* Doc flavor with MIME type = {@code "text/html; charset=us-ascii"},710* print data representation class name = {@code "[B"} (byte array).711*/712public static final BYTE_ARRAY TEXT_HTML_US_ASCII =713new BYTE_ARRAY ("text/html; charset=us-ascii");714715716/**717* Doc flavor with MIME type = {@code "application/pdf"}, print data718* representation class name = {@code "[B"} (byte array).719*/720public static final BYTE_ARRAY PDF = new BYTE_ARRAY ("application/pdf");721722/**723* Doc flavor with MIME type = {@code "application/postscript"}, print724* data representation class name = {@code "[B"} (byte array).725*/726public static final BYTE_ARRAY POSTSCRIPT =727new BYTE_ARRAY ("application/postscript");728729/**730* Doc flavor with MIME type = {@code "application/vnd.hp-PCL"}, print731* data representation class name = {@code "[B"} (byte array).732*/733public static final BYTE_ARRAY PCL =734new BYTE_ARRAY ("application/vnd.hp-PCL");735736/**737* Doc flavor with MIME type = {@code "image/gif"}, print data738* representation class name = {@code "[B"} (byte array).739*/740public static final BYTE_ARRAY GIF = new BYTE_ARRAY ("image/gif");741742/**743* Doc flavor with MIME type = {@code "image/jpeg"}, print data744* representation class name = {@code "[B"} (byte array).745*/746public static final BYTE_ARRAY JPEG = new BYTE_ARRAY ("image/jpeg");747748/**749* Doc flavor with MIME type = {@code "image/png"}, print data750* representation class name = {@code "[B"} (byte array).751*/752public static final BYTE_ARRAY PNG = new BYTE_ARRAY ("image/png");753754/**755* Doc flavor with MIME type = {@code "application/octet-stream"}, print756* data representation class name = {@code "[B"} (byte array). The757* client must determine that data described using this758* {@code DocFlavor} is valid for the printer.759*/760public static final BYTE_ARRAY AUTOSENSE =761new BYTE_ARRAY ("application/octet-stream");762}763764/**765* Class {@code DocFlavor.INPUT_STREAM} provides predefined static constant766* {@code DocFlavor} objects for example doc flavors using a byte stream767* ({@link java.io.InputStream java.io.InputStream}) as the print data768* representation class.769*770* @author Alan Kaminsky771*/772public static class INPUT_STREAM extends DocFlavor {773774/**775* Use serialVersionUID from JDK 1.4 for interoperability.776*/777@Serial778private static final long serialVersionUID = -7045842700749194127L;779780/**781* Constructs a new doc flavor with the given MIME type and a print data782* representation class name of {@code "java.io.InputStream"} (byte783* stream).784*785* @param mimeType MIME media type string786* @throws NullPointerException if {@code mimeType} is {@code null}787* @throws IllegalArgumentException if {@code mimeType} does not obey788* the syntax for a MIME media type string.789*/790public INPUT_STREAM (String mimeType) {791super (mimeType, "java.io.InputStream");792}793794/**795* Doc flavor with MIME type = {@code "text/plain"}, encoded in the host796* platform encoding. See {@link DocFlavor#hostEncoding hostEncoding}.797* Print data representation class name = {@code "java.io.InputStream"}798* (byte stream).799*/800public static final INPUT_STREAM TEXT_PLAIN_HOST =801new INPUT_STREAM ("text/plain; charset="+hostEncoding);802803/**804* Doc flavor with MIME type = {@code "text/plain; charset=utf-8"},805* print data representation class name = {@code "java.io.InputStream"}806* (byte stream).807*/808public static final INPUT_STREAM TEXT_PLAIN_UTF_8 =809new INPUT_STREAM ("text/plain; charset=utf-8");810811/**812* Doc flavor with MIME type = {@code "text/plain; charset=utf-16"},813* print data representation class name = {@code "java.io.InputStream"}814* (byte stream).815*/816public static final INPUT_STREAM TEXT_PLAIN_UTF_16 =817new INPUT_STREAM ("text/plain; charset=utf-16");818819/**820* Doc flavor with MIME type = {@code "text/plain; charset=utf-16be"}821* (big-endian byte ordering), print data representation class name =822* {@code "java.io.InputStream"} (byte stream).823*/824public static final INPUT_STREAM TEXT_PLAIN_UTF_16BE =825new INPUT_STREAM ("text/plain; charset=utf-16be");826827/**828* Doc flavor with MIME type = {@code "text/plain; charset=utf-16le"}829* (little-endian byte ordering), print data representation class name =830* {@code "java.io.InputStream"} (byte stream).831*/832public static final INPUT_STREAM TEXT_PLAIN_UTF_16LE =833new INPUT_STREAM ("text/plain; charset=utf-16le");834835/**836* Doc flavor with MIME type = {@code "text/plain; charset=us-ascii"},837* print data representation class name = {@code "java.io.InputStream"}838* (byte stream).839*/840public static final INPUT_STREAM TEXT_PLAIN_US_ASCII =841new INPUT_STREAM ("text/plain; charset=us-ascii");842843/**844* Doc flavor with MIME type = {@code "text/html"}, encoded in the host845* platform encoding. See {@link DocFlavor#hostEncoding hostEncoding}.846* Print data representation class name = {@code "java.io.InputStream"}847* (byte stream).848*/849public static final INPUT_STREAM TEXT_HTML_HOST =850new INPUT_STREAM ("text/html; charset="+hostEncoding);851852/**853* Doc flavor with MIME type = {@code "text/html; charset=utf-8"}, print854* data representation class name = {@code "java.io.InputStream"} (byte855* stream).856*/857public static final INPUT_STREAM TEXT_HTML_UTF_8 =858new INPUT_STREAM ("text/html; charset=utf-8");859860/**861* Doc flavor with MIME type = {@code "text/html; charset=utf-16"},862* print data representation class name = {@code "java.io.InputStream"}863* (byte stream).864*/865public static final INPUT_STREAM TEXT_HTML_UTF_16 =866new INPUT_STREAM ("text/html; charset=utf-16");867868/**869* Doc flavor with MIME type = {@code "text/html; charset=utf-16be"}870* (big-endian byte ordering), print data representation class name =871* {@code "java.io.InputStream"} (byte stream).872*/873public static final INPUT_STREAM TEXT_HTML_UTF_16BE =874new INPUT_STREAM ("text/html; charset=utf-16be");875876/**877* Doc flavor with MIME type = {@code "text/html; charset=utf-16le"}878* (little-endian byte ordering), print data representation class name =879* {@code "java.io.InputStream"} (byte stream).880*/881public static final INPUT_STREAM TEXT_HTML_UTF_16LE =882new INPUT_STREAM ("text/html; charset=utf-16le");883884/**885* Doc flavor with MIME type = {@code "text/html; charset=us-ascii"},886* print data representation class name = {@code "java.io.InputStream"}887* (byte stream).888*/889public static final INPUT_STREAM TEXT_HTML_US_ASCII =890new INPUT_STREAM ("text/html; charset=us-ascii");891892/**893* Doc flavor with MIME type = {@code "application/pdf"}, print data894* representation class name = {@code "java.io.InputStream"} (byte895* stream).896*/897public static final INPUT_STREAM PDF = new INPUT_STREAM ("application/pdf");898899/**900* Doc flavor with MIME type = {@code "application/postscript"}, print901* data representation class name = {@code "java.io.InputStream"} (byte902* stream).903*/904public static final INPUT_STREAM POSTSCRIPT =905new INPUT_STREAM ("application/postscript");906907/**908* Doc flavor with MIME type = {@code "application/vnd.hp-PCL"}, print909* data representation class name = {@code "java.io.InputStream"} (byte910* stream).911*/912public static final INPUT_STREAM PCL =913new INPUT_STREAM ("application/vnd.hp-PCL");914915/**916* Doc flavor with MIME type = {@code "image/gif"}, print data917* representation class name = {@code "java.io.InputStream"} (byte918* stream).919*/920public static final INPUT_STREAM GIF = new INPUT_STREAM ("image/gif");921922/**923* Doc flavor with MIME type = {@code "image/jpeg"}, print data924* representation class name = {@code "java.io.InputStream"} (byte925* stream).926*/927public static final INPUT_STREAM JPEG = new INPUT_STREAM ("image/jpeg");928929/**930* Doc flavor with MIME type = {@code "image/png"}, print data931* representation class name = {@code "java.io.InputStream"} (byte932* stream).933*/934public static final INPUT_STREAM PNG = new INPUT_STREAM ("image/png");935936/**937* Doc flavor with MIME type = {@code "application/octet-stream"}, print938* data representation class name = {@code "java.io.InputStream"} (byte939* stream). The client must determine that data described using this940* {@code DocFlavor} is valid for the printer.941*/942public static final INPUT_STREAM AUTOSENSE =943new INPUT_STREAM ("application/octet-stream");944}945946/**947* Class {@code DocFlavor.URL} provides predefined static constant948* {@code DocFlavor} objects. For example doc flavors using a Uniform949* Resource Locator ({@link java.net.URL java.net.URL}) as the print data950* representation class.951*952* @author Alan Kaminsky953*/954public static class URL extends DocFlavor {955956/**957* Use serialVersionUID from JDK 1.4 for interoperability.958*/959@Serial960private static final long serialVersionUID = 2936725788144902062L;961962/**963* Constructs a new doc flavor with the given MIME type and a print data964* representation class name of {@code "java.net.URL"}.965*966* @param mimeType MIME media type string967* @throws NullPointerException if {@code mimeType} is {@code null}968* @throws IllegalArgumentException if {@code mimeType} does not obey969* the syntax for a MIME media type string970*/971public URL (String mimeType) {972super (mimeType, "java.net.URL");973}974975/**976* Doc flavor with MIME type = {@code "text/plain"}, encoded in the host977* platform encoding. See {@link DocFlavor#hostEncoding hostEncoding}.978* Print data representation class name = {@code "java.net.URL"} (byte979* stream).980*/981public static final URL TEXT_PLAIN_HOST =982new URL ("text/plain; charset="+hostEncoding);983984/**985* Doc flavor with MIME type = {@code "text/plain; charset=utf-8"},986* print data representation class name = {@code "java.net.URL"} (byte987* stream).988*/989public static final URL TEXT_PLAIN_UTF_8 =990new URL ("text/plain; charset=utf-8");991992/**993* Doc flavor with MIME type = {@code "text/plain; charset=utf-16"},994* print data representation class name = {@code java.net.URL""} (byte995* stream).996*/997public static final URL TEXT_PLAIN_UTF_16 =998new URL ("text/plain; charset=utf-16");9991000/**1001* Doc flavor with MIME type = {@code "text/plain; charset=utf-16be"}1002* (big-endian byte ordering), print data representation class name =1003* {@code "java.net.URL"} (byte stream).1004*/1005public static final URL TEXT_PLAIN_UTF_16BE =1006new URL ("text/plain; charset=utf-16be");10071008/**1009* Doc flavor with MIME type = {@code "text/plain; charset=utf-16le"}1010* (little-endian byte ordering), print data representation class name =1011* {@code "java.net.URL"} (byte stream).1012*/1013public static final URL TEXT_PLAIN_UTF_16LE =1014new URL ("text/plain; charset=utf-16le");10151016/**1017* Doc flavor with MIME type = {@code "text/plain; charset=us-ascii"},1018* print data representation class name = {@code "java.net.URL"} (byte1019* stream).1020*/1021public static final URL TEXT_PLAIN_US_ASCII =1022new URL ("text/plain; charset=us-ascii");10231024/**1025* Doc flavor with MIME type = {@code "text/html"}, encoded in the host1026* platform encoding. See {@link DocFlavor#hostEncoding hostEncoding}.1027* Print data representation class name = {@code "java.net.URL"} (byte1028* stream).1029*/1030public static final URL TEXT_HTML_HOST =1031new URL ("text/html; charset="+hostEncoding);10321033/**1034* Doc flavor with MIME type = {@code "text/html; charset=utf-8"}, print1035* data representation class name = {@code "java.net.URL"} (byte1036* stream).1037*/1038public static final URL TEXT_HTML_UTF_8 =1039new URL ("text/html; charset=utf-8");10401041/**1042* Doc flavor with MIME type = {@code "text/html; charset=utf-16"},1043* print data representation class name = {@code "java.net.URL"} (byte1044* stream).1045*/1046public static final URL TEXT_HTML_UTF_16 =1047new URL ("text/html; charset=utf-16");10481049/**1050* Doc flavor with MIME type = {@code "text/html; charset=utf-16be"}1051* (big-endian byte ordering), print data representation class name =1052* {@code "java.net.URL"} (byte stream).1053*/1054public static final URL TEXT_HTML_UTF_16BE =1055new URL ("text/html; charset=utf-16be");10561057/**1058* Doc flavor with MIME type = {@code "text/html; charset=utf-16le"}1059* (little-endian byte ordering), print data representation class name =1060* {@code "java.net.URL"} (byte stream).1061*/1062public static final URL TEXT_HTML_UTF_16LE =1063new URL ("text/html; charset=utf-16le");10641065/**1066* Doc flavor with MIME type = {@code "text/html; charset=us-ascii"},1067* print data representation class name = {@code "java.net.URL"} (byte1068* stream).1069*/1070public static final URL TEXT_HTML_US_ASCII =1071new URL ("text/html; charset=us-ascii");10721073/**1074* Doc flavor with MIME type = {@code "application/pdf"}, print data1075* representation class name = {@code "java.net.URL"}.1076*/1077public static final URL PDF = new URL ("application/pdf");10781079/**1080* Doc flavor with MIME type = {@code "application/postscript"}, print1081* data representation class name = {@code "java.net.URL"}.1082*/1083public static final URL POSTSCRIPT = new URL ("application/postscript");10841085/**1086* Doc flavor with MIME type = {@code "application/vnd.hp-PCL"}, print1087* data representation class name = {@code "java.net.URL"}.1088*/1089public static final URL PCL = new URL ("application/vnd.hp-PCL");10901091/**1092* Doc flavor with MIME type = {@code "image/gif"}, print data1093* representation class name = {@code "java.net.URL"}.1094*/1095public static final URL GIF = new URL ("image/gif");10961097/**1098* Doc flavor with MIME type = {@code "image/jpeg"}, print data1099* representation class name = {@code "java.net.URL"}.1100*/1101public static final URL JPEG = new URL ("image/jpeg");11021103/**1104* Doc flavor with MIME type = {@code "image/png"}, print data1105* representation class name = {@code "java.net.URL"}.1106*/1107public static final URL PNG = new URL ("image/png");11081109/**1110* Doc flavor with MIME type = {@code "application/octet-stream"}, print1111* data representation class name = {@code "java.net.URL"}. The client1112* must determine that data described using this {@code DocFlavor} is1113* valid for the printer.1114*/1115public static final URL AUTOSENSE = new URL ("application/octet-stream");1116}11171118/**1119* Class {@code DocFlavor.CHAR_ARRAY} provides predefined static constant1120* {@code DocFlavor} objects for example doc flavors using a character array1121* ({@code char[]}) as the print data representation class. As such, the1122* character set is Unicode.1123*1124* @author Alan Kaminsky1125*/1126public static class CHAR_ARRAY extends DocFlavor {11271128/**1129* Use serialVersionUID from JDK 1.4 for interoperability.1130*/1131@Serial1132private static final long serialVersionUID = -8720590903724405128L;11331134/**1135* Constructs a new doc flavor with the given MIME type and a print data1136* representation class name of {@code "[C"} (character array).1137*1138* @param mimeType MIME media type string. If it is a text media type,1139* it is assumed to contain a {@code "charset=utf-16"}1140* parameter.1141* @throws NullPointerException if {@code mimeType} is {@code null}1142* @throws IllegalArgumentException if {@code mimeType} does not obey1143* the syntax for a MIME media type string1144*/1145public CHAR_ARRAY (String mimeType) {1146super (mimeType, "[C");1147}11481149/**1150* Doc flavor with MIME type = {@code "text/plain; charset=utf-16"},1151* print data representation class name = {@code "[C"} (character1152* array).1153*/1154public static final CHAR_ARRAY TEXT_PLAIN =1155new CHAR_ARRAY ("text/plain; charset=utf-16");11561157/**1158* Doc flavor with MIME type = {@code "text/html; charset=utf-16"},1159* print data representation class name = {@code "[C"} (character1160* array).1161*/1162public static final CHAR_ARRAY TEXT_HTML =1163new CHAR_ARRAY ("text/html; charset=utf-16");1164}11651166/**1167* Class {@code DocFlavor.STRING} provides predefined static constant1168* {@code DocFlavor} objects for example doc flavors using a string1169* ({@link String java.lang.String}) as the print data representation class.1170* As such, the character set is Unicode.1171*1172* @author Alan Kaminsky1173*/1174public static class STRING extends DocFlavor {11751176/**1177* Use serialVersionUID from JDK 1.4 for interoperability.1178*/1179@Serial1180private static final long serialVersionUID = 4414407504887034035L;11811182/**1183* Constructs a new doc flavor with the given MIME type and a print data1184* representation class name of {@code "java.lang.String"}.1185*1186* @param mimeType MIME media type string. If it is a text media type,1187* it is assumed to contain a {@code "charset=utf-16"}1188* parameter.1189* @throws NullPointerException if {@code mimeType} is {@code null}1190* @throws IllegalArgumentException if {@code mimeType} does not obey1191* the syntax for a MIME media type string1192*/1193public STRING (String mimeType) {1194super (mimeType, "java.lang.String");1195}11961197/**1198* Doc flavor with MIME type = {@code "text/plain; charset=utf-16"},1199* print data representation class name = {@code "java.lang.String"}.1200*/1201public static final STRING TEXT_PLAIN =1202new STRING ("text/plain; charset=utf-16");12031204/**1205* Doc flavor with MIME type = {@code "text/html; charset=utf-16"},1206* print data representation class name = {@code "java.lang.String"}.1207*/1208public static final STRING TEXT_HTML =1209new STRING ("text/html; charset=utf-16");1210}12111212/**1213* Class {@code DocFlavor.READER} provides predefined static constant1214* {@code DocFlavor} objects for example doc flavors using a character1215* stream ({@link java.io.Reader java.io.Reader}) as the print data1216* representation class. As such, the character set is Unicode.1217*1218* @author Alan Kaminsky1219*/1220public static class READER extends DocFlavor {12211222/**1223* Use serialVersionUID from JDK 1.4 for interoperability.1224*/1225@Serial1226private static final long serialVersionUID = 7100295812579351567L;12271228/**1229* Constructs a new doc flavor with the given MIME type and a print data1230* representation class name of {@code "java.io.Reader"} (character1231* stream).1232*1233* @param mimeType MIME media type string. If it is a text media type,1234* it is assumed to contain a {@code "charset=utf-16"}1235* parameter.1236* @throws NullPointerException if {@code mimeType} is {@code null}1237* @throws IllegalArgumentException if {@code mimeType} does not obey1238* the syntax for a MIME media type string1239*/1240public READER (String mimeType) {1241super (mimeType, "java.io.Reader");1242}12431244/**1245* Doc flavor with MIME type = {@code "text/plain; charset=utf-16"},1246* print data representation class name = {@code "java.io.Reader"}1247* (character stream).1248*/1249public static final READER TEXT_PLAIN =1250new READER ("text/plain; charset=utf-16");12511252/**1253* Doc flavor with MIME type = {@code "text/html; charset=utf-16"},1254* print data representation class name = {@code "java.io.Reader"}1255* (character stream).1256*/1257public static final READER TEXT_HTML =1258new READER ("text/html; charset=utf-16");12591260}12611262/**1263* Class {@code DocFlavor.SERVICE_FORMATTED} provides predefined static1264* constant {@code DocFlavor} objects for example doc flavors for service1265* formatted print data.1266*1267* @author Alan Kaminsky1268*/1269public static class SERVICE_FORMATTED extends DocFlavor {12701271/**1272* Use serialVersionUID from JDK 1.4 for interoperability.1273*/1274@Serial1275private static final long serialVersionUID = 6181337766266637256L;12761277/**1278* Constructs a new doc flavor with a MIME type of1279* {@code "application/x-java-jvm-local-objectref"} indicating service1280* formatted print data and the given print data representation class1281* name.1282*1283* @param className fully-qualified representation class name1284* @throws NullPointerException if {@code className} is {@code null}1285*/1286public SERVICE_FORMATTED (String className) {1287super ("application/x-java-jvm-local-objectref", className);1288}12891290/**1291* Service formatted print data doc flavor with print data1292* representation class name =1293* {@code "java.awt.image.renderable.RenderableImage"} (renderable image1294* object).1295*/1296public static final SERVICE_FORMATTED RENDERABLE_IMAGE =1297new SERVICE_FORMATTED("java.awt.image.renderable.RenderableImage");12981299/**1300* Service formatted print data doc flavor with print data1301* representation class name = {@code "java.awt.print.Printable"}1302* (printable object).1303*/1304public static final SERVICE_FORMATTED PRINTABLE =1305new SERVICE_FORMATTED ("java.awt.print.Printable");13061307/**1308* Service formatted print data doc flavor with print data1309* representation class name = {@code "java.awt.print.Pageable"}1310* (pageable object).1311*/1312public static final SERVICE_FORMATTED PAGEABLE =1313new SERVICE_FORMATTED ("java.awt.print.Pageable");13141315}1316}131713181319