1 /*
   2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.print;
  27 
  28 import java.io.OutputStream;
  29 
  30 /**
  31  * This class extends {@link PrintService} and represents a print service that
  32  * prints data in different formats to a client-provided output stream. This is
  33  * principally intended for services where the output format is a document type
  34  * suitable for viewing or archiving. The output format must be declared as a
  35  * mime type. This is equivalent to an output document flavor where the
  36  * representation class is always "java.io.OutputStream" An instance of the
  37  * {@code StreamPrintService} class is obtained from a
  38  * {@link StreamPrintServiceFactory} instance.
  39  * <p>
  40  * Note that a {@code StreamPrintService} is different from a
  41  * {@code PrintService}, which supports a
  42  * {@link javax.print.attribute.standard.Destination Destination} attribute. A
  43  * {@code StreamPrintService} always requires an output stream, whereas a
  44  * {@code PrintService} optionally accepts a {@code Destination}. A
  45  * {@code StreamPrintService} has no default destination for its formatted
  46  * output. Additionally a {@code StreamPrintService} is expected to generate
  47  * output in a format useful in other contexts. {@code StreamPrintService}'s are
  48  * not expected to support the {@code Destination} attribute.
  49  */
  50 public abstract class StreamPrintService implements PrintService {
  51 
  52     /**
  53      * The output stream to which this service will send formatted print data.
  54      */
  55     private OutputStream outStream;
  56 
  57     /**
  58      * Whether or not this {@code StreamPrintService} has been disposed.
  59      */
  60     private boolean disposed = false;
  61 
  62     /**
  63      * Constructs a {@code StreamPrintService} object.
  64      */
  65     private StreamPrintService() {
  66     };
  67 
  68     /**
  69      * Constructs a {@code StreamPrintService} object.
  70      *
  71      * @param  out stream to which to send formatted print data
  72      */
  73     protected StreamPrintService(OutputStream out) {
  74         this.outStream = out;
  75     }
  76 
  77     /**
  78      * Gets the output stream.
  79      *
  80      * @return the stream to which this service will send formatted print data
  81      */
  82     public OutputStream getOutputStream() {
  83         return outStream;
  84     }
  85 
  86     /**
  87      * Returns the document format emitted by this print service. Must be in
  88      * mimetype format, compatible with the mime type components of
  89      * {@code DocFlavors}
  90      *
  91      * @return mime type identifying the output format
  92      * @see DocFlavor
  93      */
  94     public abstract String getOutputFormat();
  95 
  96     /**
  97      * Disposes this {@code StreamPrintService}. If a stream service cannot be
  98      * re-used, it must be disposed to indicate this. Typically the client will
  99      * call this method. Services which write data which cannot meaningfully be
 100      * appended to may also dispose the stream. This does not close the stream.
 101      * It just marks it as not for further use by this service.
 102      */
 103     public void dispose() {
 104         disposed = true;
 105     }
 106 
 107     /**
 108      * Returns a {@code boolean} indicating whether or not this
 109      * {@code StreamPrintService} has been disposed. If this object has been
 110      * disposed, will return {@code true}. Used by services and client
 111      * applications to recognize streams to which no further data should be
 112      * written.
 113      *
 114      * @return {@code true} if this {@code StreamPrintService} has been
 115      *         disposed; {@code false} otherwise
 116      */
 117     public boolean isDisposed() {
 118         return disposed;
 119     }
 120 }