docflavor.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 916 行 · 第 1/3 页

JAVA
916
字号
/* DocFlavor.java --   Copyright (C) 2004, 2006 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.print;import java.io.IOException;import java.io.ObjectInputStream;import java.io.Serializable;import java.io.StreamTokenizer;import java.io.StringReader;import java.nio.charset.Charset;import java.util.Iterator;import java.util.Map;import java.util.TreeMap;/** * <code>DocFlavor</code> provides a description of the format in which the  * print data will be supplied in a print job to the print service. * <p> * A doc flavor consists of two parts: * <ul> * <li> * The MIME type (Multipurpose Internet Mail Extensions types as described  * in RFC 2045/2046) specifying the media format of the print data. * </li><li> * The representation class name which is the fully qualified name of the  * class providing the print data to the print job. For example if the print  * data is supplied as a byte array the representation class name will be  * <code>"[B"</code> or for an input stream <code>"java.io.InputStream"</code>. * </li> * </ul> * The <code>DocFlavor</code> class is therefore used in several places in the  * Java Print Service API. A print service provides its supported document  * flavors as an array of DocFlavor objects and a print job gets the flavor of * its data to print from the <code>Doc</code> object provided as a DocFlavor * instance. * </p> * <p> * It has to be differentiated between <b>client formatted</b> and <b>service  * formatted</b> print data. Client formatted print data is already provided  * formatted by the client e.g. in an image format or as postscript. For  * service formatted print data, the Java Print Service instance produces  * the formatted print data. Here the doc flavor's representation class name  * does specify an interface instead of the actual print data source. The  * print service will call the methods of the given implementation of this * interface with a special Graphics object capable of producing formatted * print data from the graphics routines inside the interface methods. * </p> * <p> * <h3>Client formatted print data document flavors</h3> * The print service uses the representation class of the doc flavor to know  * how to retrieve the print data. If the representation class is a  * <code>URL</code> it will open the URL to read the print data from it. If it is  * a <code>byte[]</code> it will directly use the array and send it to the  * printer. There are predefined doc flavor as inner class for the most common  * representation class types: * <ul> * <li>Character arrays (<code>char[]</code>): The characters of the array  * represent the print data.</li> * <li>Character streams (<code>java.io.Reader</code>): The whole characters  * read from the stream represent the print data.</li> * <li>String (<code>java.lang.String</code>): The characters of the String  * represent the print data.</li> * <li>Byte arrays (<code>byte[]</code>): The bytes of the array represent the  * print data. Encoding if text content is given in the mime type.</li> * <li>Byte streams (<code>java.io.InputStream</code>): The whole bytes read  * from the stream represent the print data. If text content the encoding is  * specified in the mime type.</li> * <li>Uniform Resource Locator (<code>java.net.URL</code>): The bytes read  * from the stream through opening of the URL represent the print data.  * If text content the encoding is specified in the mime type.</li></li> * </ul> * </p> * <p> * <h3>Service formatted print data document flavors</h3> * The print service uses the provided object implementing the interface * specified by the representation class to produce the formatted print data.  * The mime type of service formatted data is always  * <code>"application/x-java-jvm-local-objectref"</code> to signal the local  * reference to the print data object implementing the interface. Predefined * doc flavor classes exist as an inner class for the three available interface  * to produce print data: * <ul> * <li>Pageable object (<code>java.awt.print.Pageable</code>): A pageable object * is supplied to the print service. The print service will call the methods of * the interface with a Grahics object to produce the formatted print data.</li> * <li>Printable object (<code>java.awt.print.Printable</code>): A printable object * is supplied to the print service. The print service will call the methods of * the interface with a Grahics object to produce the formatted print data.</li> * <li>Renderable Image object  * (<code>java.awt.image.renderable.RenderableImage</code>): A renderable image * object is supplied to the print service. The print service calls methods of * this interface to obtain the image to be printed.</li> * </ul> * </p> *  * @author Michael Koch (konqueror@gmx.de) * @author Wolfgang Baer (WBaer@gmx.de) */public class DocFlavor implements Cloneable, Serializable{  /**   * Predefined static <code>DocFlavor</code> objects for document   * types which use a byte array for the print data representation.   * <p>All the defined doc flavors have a print data representation    * classname of "[B" (byte array).</p>   *    * @author Michael Koch (konqueror@gmx.de)   */  public static class BYTE_ARRAY    extends DocFlavor  {    private static final long serialVersionUID = -9065578006593857475L;    /**     * Byte array doc flavor with a MIME Type of "application/octet-stream".     */    public static final BYTE_ARRAY AUTOSENSE = new BYTE_ARRAY("application/octet-stream");    /**     * Byte array doc flavor with a MIME Type of "image/gif".     */    public static final BYTE_ARRAY GIF = new BYTE_ARRAY("image/gif");    /**     * Byte array doc flavor with a MIME Type of "image/jpeg".     */    public static final BYTE_ARRAY JPEG = new BYTE_ARRAY("image/jpeg");    /**     * Byte array doc flavor with a MIME Type of "application/vnd.hp-PCL".     */    public static final BYTE_ARRAY PCL = new BYTE_ARRAY("application/vnd.hp-PCL");    /**     * Byte array doc flavor with a MIME Type of "application/pdf".     */    public static final BYTE_ARRAY PDF = new BYTE_ARRAY("application/pdf");    /**     * Byte array doc flavor with a MIME Type of "image/png".     */    public static final BYTE_ARRAY PNG = new BYTE_ARRAY("image/png");    /**     * Byte array doc flavor with a MIME Type of "application/postscript".     */    public static final BYTE_ARRAY POSTSCRIPT = new BYTE_ARRAY("application/postscript");    /**     * Byte array doc flavor with a MIME Type of "text/html" in the host encoding.     */    public static final BYTE_ARRAY TEXT_HTML_HOST = new BYTE_ARRAY("text/html; charset=" + hostEncoding);    /**     * Byte array doc flavor with a MIME Type of "text/html; charset=us-ascii".     */    public static final BYTE_ARRAY TEXT_HTML_US_ASCII = new BYTE_ARRAY("text/html; charset=us-ascii");    /**     * Byte array doc flavor with a MIME Type of "text/html; charset=utf-16".     */    public static final BYTE_ARRAY TEXT_HTML_UTF_16 = new BYTE_ARRAY("text/html; charset=utf-16");    /**     * Byte array doc flavor with a MIME Type of "text/html; charset=utf-16be".     */    public static final BYTE_ARRAY TEXT_HTML_UTF_16BE = new BYTE_ARRAY("text/html; charset=utf-16be");    /**     * Byte array doc flavor with a MIME Type of "text/html; charset=utf-16le".     */    public static final BYTE_ARRAY TEXT_HTML_UTF_16LE = new BYTE_ARRAY("text/html; charset=utf-16le");    /**     * Byte array doc flavor with a MIME Type of "text/html; charset=utf-8".     */    public static final BYTE_ARRAY TEXT_HTML_UTF_8 = new BYTE_ARRAY("text/html; charset=utf-8");    /**     * Byte array doc flavor with a MIME Type of "text/plain" in the host encoding.     */    public static final BYTE_ARRAY TEXT_PLAIN_HOST = new BYTE_ARRAY("text/plain; charset=" + hostEncoding);    /**     * Byte array doc flavor with a MIME Type of "text/plain; charset=us-ascii".     */    public static final BYTE_ARRAY TEXT_PLAIN_US_ASCII = new BYTE_ARRAY("text/plain; charset=us-ascii");        /**     * Byte array doc flavor with a MIME Type of "text/plain; charset=utf-16".     */    public static final BYTE_ARRAY TEXT_PLAIN_UTF_16 = new BYTE_ARRAY("text/plain; charset=utf-16");    /**     * Byte array doc flavor with a MIME Type of "text/plain; charset=utf-16be".     */    public static final BYTE_ARRAY TEXT_PLAIN_UTF_16BE = new BYTE_ARRAY("text/plain; charset=utf-16be");    /**     * Byte array doc flavor with a MIME Type of "text/plain; charset=utf-16le".     */    public static final BYTE_ARRAY TEXT_PLAIN_UTF_16LE = new BYTE_ARRAY("text/plain; charset=utf-16le");    /**     * Byte array doc flavor with a MIME Type of "text/plain; charset=utf-8".     */    public static final BYTE_ARRAY TEXT_PLAIN_UTF_8 = new BYTE_ARRAY("text/plain; charset=utf-8");        /**     * Constructor for doc flavor objects with the given MIME type      * and a print data representation class name of "[B".     *      * @param mimeType the mime type string     *      * @throws NullPointerException if mimeType is <code>null</code>.     * @throws IllegalArgumentException if mimeType has the wrong syntax.     */    public BYTE_ARRAY(String mimeType)    {      super(mimeType, "[B");    }  }    /**   * Predefined static <code>DocFlavor</code> objects for document   * types which use a char array for the print data representation.   * <p>All the defined doc flavors have a print data representation    * classname of "[C" (char array).</p>   *    * @author Michael Koch (konqueror@gmx.de)   */  public static class CHAR_ARRAY    extends DocFlavor  {    private static final long serialVersionUID = -8720590903724405128L;        /**     * Char array doc flavor with a MIME Type of "text/html; charset=utf-16".     */    public static final DocFlavor.CHAR_ARRAY TEXT_HTML = new CHAR_ARRAY("text/html; charset=utf-16");    /**     * Char array doc flavor with a MIME Type of "text/plain; charset=utf-16".     */    public static final DocFlavor.CHAR_ARRAY TEXT_PLAIN = new CHAR_ARRAY("text/plain; charset=utf-16");    /**     * Constructor for doc flavor objects with the given MIME type      * and a print data representation class name of "[C".     *      * @param mimeType the mime type string     *      * @throws NullPointerException if mimeType is <code>null</code>.     * @throws IllegalArgumentException if mimeType has the wrong syntax.     */    public CHAR_ARRAY(String mimeType)    {      super(mimeType, "[C");    }  }    /**   * Predefined static <code>DocFlavor</code> objects for document   * types which use an InputStream to retrieve the print data.   * <p>All the defined doc flavors have a print data representation    * classname of "java.io.InputStream".</p>   *    * @author Michael Koch (konqueror@gmx.de)   */  public static class INPUT_STREAM    extends DocFlavor  {    private static final long serialVersionUID = -7045842700749194127L;    /**     * InputStream doc flavor with a MIME Type of "application/octet-stream".     */    public static final INPUT_STREAM AUTOSENSE = new INPUT_STREAM("application/octet-stream");    /**     * InputStream doc flavor with a MIME Type of "image/gif".     */    public static final INPUT_STREAM GIF = new INPUT_STREAM("image/gif");    /**     * InputStream doc flavor with a MIME Type of "image/jpeg".     */    public static final INPUT_STREAM JPEG = new INPUT_STREAM("image/jpeg");    /**     * InputStream doc flavor with a MIME Type of "application/vnd.hp-PCL".     */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?