Path: blob/master/src/java.desktop/share/classes/javax/print/StreamPrintService.java
41153 views
/*1* Copyright (c) 2000, 2017, 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.OutputStream;2829/**30* This class extends {@link PrintService} and represents a print service that31* prints data in different formats to a client-provided output stream. This is32* principally intended for services where the output format is a document type33* suitable for viewing or archiving. The output format must be declared as a34* mime type. This is equivalent to an output document flavor where the35* representation class is always "java.io.OutputStream" An instance of the36* {@code StreamPrintService} class is obtained from a37* {@link StreamPrintServiceFactory} instance.38* <p>39* Note that a {@code StreamPrintService} is different from a40* {@code PrintService}, which supports a41* {@link javax.print.attribute.standard.Destination Destination} attribute. A42* {@code StreamPrintService} always requires an output stream, whereas a43* {@code PrintService} optionally accepts a {@code Destination}. A44* {@code StreamPrintService} has no default destination for its formatted45* output. Additionally a {@code StreamPrintService} is expected to generate46* output in a format useful in other contexts. {@code StreamPrintService}'s are47* not expected to support the {@code Destination} attribute.48*/49public abstract class StreamPrintService implements PrintService {5051/**52* The output stream to which this service will send formatted print data.53*/54private OutputStream outStream;5556/**57* Whether or not this {@code StreamPrintService} has been disposed.58*/59private boolean disposed = false;6061/**62* Constructs a {@code StreamPrintService} object.63*/64private StreamPrintService() {65};6667/**68* Constructs a {@code StreamPrintService} object.69*70* @param out stream to which to send formatted print data71*/72protected StreamPrintService(OutputStream out) {73this.outStream = out;74}7576/**77* Gets the output stream.78*79* @return the stream to which this service will send formatted print data80*/81public OutputStream getOutputStream() {82return outStream;83}8485/**86* Returns the document format emitted by this print service. Must be in87* mimetype format, compatible with the mime type components of88* {@code DocFlavors}89*90* @return mime type identifying the output format91* @see DocFlavor92*/93public abstract String getOutputFormat();9495/**96* Disposes this {@code StreamPrintService}. If a stream service cannot be97* re-used, it must be disposed to indicate this. Typically the client will98* call this method. Services which write data which cannot meaningfully be99* appended to may also dispose the stream. This does not close the stream.100* It just marks it as not for further use by this service.101*/102public void dispose() {103disposed = true;104}105106/**107* Returns a {@code boolean} indicating whether or not this108* {@code StreamPrintService} has been disposed. If this object has been109* disposed, will return {@code true}. Used by services and client110* applications to recognize streams to which no further data should be111* written.112*113* @return {@code true} if this {@code StreamPrintService} has been114* disposed; {@code false} otherwise115*/116public boolean isDisposed() {117return disposed;118}119}120121122