Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/print/Doc.java
38829 views
/*1* Copyright (c) 2000, 2013, 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.InputStream;28import java.io.IOException;29import java.io.Reader;3031import javax.print.attribute.DocAttributeSet;323334/**35* Interface Doc specifies the interface for an object that supplies one piece36* of print data for a Print Job. "Doc" is a short, easy-to-pronounce term37* that means "a piece of print data." The client passes to the Print Job an38* object that implements interface Doc, and the Print Job calls methods on39* that object to obtain the print data. The Doc interface lets a Print Job:40* <UL>41* <LI>42* Determine the format, or "doc flavor" (class {@link DocFlavor DocFlavor}),43* in which the print data is available. A doc flavor designates the print44* data format (a MIME type) and the representation class of the object45* from which the print data comes.46* <P>47* <LI>48* Obtain the print data representation object, which is an instance of the49* doc flavor's representation class. The Print Job can then obtain the actual50* print data from the representation object.51* <P>52* <LI>53* Obtain the printing attributes that specify additional characteristics of54* the doc or that specify processing instructions to be applied to the doc.55* Printing attributes are defined in package {@link javax.print.attribute56* javax.print.attribute}. The doc returns its printing attributes stored in57* an {@link javax.print.attribute.DocAttributeSet javax.print.attribute.DocAttributeSet}.58* </UL>59* <P>60* Each method in an implementation of interface Doc is permitted always to61* return the same object each time the method is called.62* This has implications63* for a Print Job or other caller of a doc object whose print data64* representation object "consumes" the print data as the caller obtains the65* print data, such as a print data representation object which is a stream.66* Once the Print Job has called {@link #getPrintData()67* getPrintData()} and obtained the stream, any further calls to68* {@link #getPrintData() getPrintData()} will return the same69* stream object upon which reading may already be in progress, <I>not</I> a new70* stream object that will re-read the print data from the beginning. Specifying71* a doc object to behave this way simplifies the implementation of doc objects,72* and is justified on the grounds that a particular doc is intended to convey73* print data only to one Print Job, not to several different Print Jobs. (To74* convey the same print data to several different Print Jobs, you have to75* create several different doc objects on top of the same print data source.)76* <P>77* Interface Doc affords considerable implementation flexibility. The print data78* might already be in existence when the doc object is constructed. In this79* case the objects returned by the doc's methods can be supplied to the doc's80* constructor, be stored in the doc ahead of time, and simply be returned when81* called for. Alternatively, the print data might not exist yet when the doc82* object is constructed. In this case the doc object might provide a "lazy"83* implementation that generates the print data representation object (and/or84* the print data) only when the Print Job calls for it (when the Print Job85* calls the {@link #getPrintData() getPrintData()} method).86* <P>87* There is no restriction on the number of client threads that may be88* simultaneously accessing the same doc. Therefore, all implementations of89* interface Doc must be designed to be multiple thread safe.90* <p>91* However there can only be one consumer of the print data obtained from a92* Doc.93* <p>94* If print data is obtained from the client as a stream, by calling Doc's95* <code>getReaderForText()</code> or <code>getStreamForBytes()</code>96* methods, or because the print data source is already an InputStream or97* Reader, then the print service should always close these streams for the98* client on all job completion conditions. With the following caveat.99* If the print data is itself a stream, the service will always close it.100* If the print data is otherwise something that can be requested as a stream,101* the service will only close the stream if it has obtained the stream before102* terminating. That is, just because a print service might request data as103* a stream does not mean that it will, with the implications that Doc104* implementors which rely on the service to close them should create such105* streams only in response to a request from the service.106* <P>107* <HR>108*/109public interface Doc {110111/**112* Determines the doc flavor in which this doc object will supply its113* piece of print data.114*115* @return Doc flavor.116*/117public DocFlavor getDocFlavor();118119/**120* Obtains the print data representation object that contains this doc121* object's piece of print data in the format corresponding to the122* supported doc flavor.123* The <CODE>getPrintData()</CODE> method returns an instance of124* the representation class whose name is given by <CODE>{@link125* #getDocFlavor() getDocFlavor()}.{@link126* DocFlavor#getRepresentationClassName()127* getRepresentationClassName()}</CODE>, and the return value can be cast128* from class Object to that representation class.129*130* @return Print data representation object.131*132* @exception IOException133* Thrown if the representation class is a stream and there was an I/O134* error while constructing the stream.135*/136public Object getPrintData() throws IOException;137138/**139* Obtains the set of printing attributes for this doc object. If the140* returned attribute set includes an instance of a particular attribute141* <I>X,</I> the printer must use that attribute value for this doc,142* overriding any value of attribute <I>X</I> in the job's attribute set.143* If the returned attribute set does not include an instance144* of a particular attribute <I>X</I> or if null is returned, the printer145* must consult the job's attribute set to obtain the value for146* attribute <I>X,</I> and if not found there, the printer must use an147* implementation-dependent default value. The returned attribute set is148* unmodifiable.149*150* @return Unmodifiable set of printing attributes for this doc, or null151* to obtain all attribute values from the job's attribute152* set.153*/154public DocAttributeSet getAttributes();155156/**157* Obtains a reader for extracting character print data from this doc.158* The Doc implementation is required to support this method if the159* DocFlavor has one of the following print data representation classes,160* and return null otherwise:161* <UL>162* <LI> char[]163* <LI> java.lang.String164* <LI> java.io.Reader165* </UL>166* The doc's print data representation object is used to construct and167* return a Reader for reading the print data as a stream of characters168* from the print data representation object.169* However, if the print data representation object is itself a Reader,170* then the print data representation object is simply returned.171* <P>172* @return Reader for reading the print data characters from this doc.173* If a reader cannot be provided because this doc does not meet174* the criteria stated above, null is returned.175*176* @exception IOException177* Thrown if there was an I/O error while creating the reader.178*/179public Reader getReaderForText() throws IOException;180181/**182* Obtains an input stream for extracting byte print data from this183* doc. The Doc implementation is required to support this method if184* the DocFlavor has one of the following print data representation185* classes, and return null otherwise:186* <UL>187* <LI> byte[]188* <LI> java.io.InputStream189* </UL>190* This doc's print data representation object is obtained, then an input191* stream for reading the print data from the print data representation192* object as a stream of bytes is created and returned. However, if the193* print data representation object is itself an input stream, then the194* print data representation object is simply returned.195* <P>196* @return Input stream for reading the print data bytes from this doc. If197* an input stream cannot be provided because this doc does not198* meet the criteria stated above, null is returned.199*200* @exception IOException201* Thrown if there was an I/O error while creating the input stream.202*/203public InputStream getStreamForBytes() throws IOException;204205}206207208