KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > print > StreamPrintService


1 /*
2  * @(#)StreamPrintService.java 1.8 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.print;
9
10 import java.io.OutputStream JavaDoc;
11
12 /**
13  * This class extends {@link PrintService} and represents a
14  * print service that prints data in different formats to a
15  * client-provided output stream.
16  * This is principally intended for services where
17  * the output format is a document type suitable for viewing
18  * or archiving.
19  * The output format must be declared as a mime type.
20  * This is equivalent to an output document flavor where the
21  * representation class is always "java.io.OutputStream"
22  * An instance of the <code>StreamPrintService</code> class is
23  * obtained from a {@link StreamPrintServiceFactory} instance.
24  * <p>
25  * Note that a <code>StreamPrintService</code> is different from a
26  * <code>PrintService</code>, which supports a
27  * {@link javax.print.attribute.standard.Destination Destination}
28  * attribute. A <code>StreamPrintService</code> always requires an output
29  * stream, whereas a <code>PrintService</code> optionally accepts a
30  * <code>Destination</code>. A <code>StreamPrintService</code>
31  * has no default destination for its formatted output.
32  * Additionally a <code>StreamPrintService</code> is expected to generate
33 output in
34  * a format useful in other contexts.
35  * StreamPrintService's are not expected to support the Destination attribute.
36  */

37
38 public abstract class StreamPrintService implements PrintService JavaDoc {
39
40     private OutputStream JavaDoc outStream;
41     private boolean disposed = false;
42
43     private StreamPrintService() {
44     };
45
46     /**
47      * Constructs a StreamPrintService object.
48      *
49      * @param out stream to which to send formatted print data.
50      */

51     protected StreamPrintService(OutputStream JavaDoc out) {
52     this.outStream = out;
53     }
54
55     /**
56      * Gets the output stream.
57      *
58      * @return the stream to which this service will send formatted print data.
59      */

60     public OutputStream JavaDoc getOutputStream() {
61     return outStream;
62     }
63
64     /**
65      * Returns the document format emitted by this print service.
66      * Must be in mimetype format, compatible with the mime type
67      * components of DocFlavors @see DocFlavor.
68      * @return mime type identifying the output format.
69      */

70     public abstract String JavaDoc getOutputFormat();
71
72     /**
73      * Disposes this <code>StreamPrintService</code>.
74      * If a stream service cannot be re-used, it must be disposed
75      * to indicate this. Typically the client will call this method.
76      * Services which write data which cannot meaningfully be appended to
77      * may also dispose the stream. This does not close the stream. It
78      * just marks it as not for further use by this service.
79      */

80     public void dispose() {
81     disposed = true;
82     }
83
84     /**
85      * Returns a <code>boolean</code> indicating whether or not
86      * this <code>StreamPrintService</code> has been disposed.
87      * If this object has been disposed, will return true.
88      * Used by services and client applications to recognize streams
89      * to which no further data should be written.
90      * @return if this <code>StreamPrintService</code> has been disposed
91      */

92     public boolean isDisposed() {
93     return disposed;
94     }
95
96 }
97
Popular Tags