< prev index next >

src/java.desktop/share/classes/javax/print/StreamPrintService.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2001, 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
  32  * print service that prints data in different formats to a
  33  * client-provided output stream.
  34  * This is principally intended for services where
  35  * the output format is a document type suitable for viewing
  36  * or archiving.
  37  * The output format must be declared as a mime type.
  38  * This is equivalent to an output document flavor where the
  39  * representation class is always "java.io.OutputStream"
  40  * An instance of the {@code StreamPrintService} class is
  41  * obtained from a {@link StreamPrintServiceFactory} instance.
  42  * <p>
  43  * Note that a {@code StreamPrintService} is different from a
  44  * {@code PrintService}, which supports a
  45  * {@link javax.print.attribute.standard.Destination Destination}
  46  * attribute.  A {@code StreamPrintService} always requires an output
  47  * stream, whereas a {@code PrintService} optionally accepts a
  48  * {@code Destination}. A {@code StreamPrintService}
  49  * has no default destination for its formatted output.
  50  * Additionally a {@code StreamPrintService} is expected to generate
  51 output in
  52  * a format useful in other contexts.
  53  * StreamPrintService's are not expected to support the Destination attribute.
  54  */
  55 
  56 public abstract class StreamPrintService implements PrintService {
  57 



  58     private OutputStream outStream;




  59     private boolean disposed = false;
  60 



  61     private StreamPrintService() {
  62     };
  63 
  64     /**
  65      * Constructs a StreamPrintService object.
  66      *
  67      * @param out  stream to which to send formatted print data.
  68      */
  69     protected StreamPrintService(OutputStream out) {
  70         this.outStream = out;
  71     }
  72 
  73     /**
  74      * Gets the output stream.
  75      *
  76      * @return the stream to which this service will send formatted print data.
  77      */
  78     public OutputStream getOutputStream() {
  79         return outStream;
  80     }
  81 
  82     /**
  83      * Returns the document format emitted by this print service.
  84      * Must be in mimetype format, compatible with the mime type
  85      * components of DocFlavors @see DocFlavor.
  86      * @return mime type identifying the output format.


  87      */
  88     public abstract String getOutputFormat();
  89 
  90     /**
  91      * Disposes this {@code StreamPrintService}.
  92      * If a stream service cannot be re-used, it must be disposed
  93      * to indicate this. Typically the client will call this method.
  94      * Services which write data which cannot meaningfully be appended to
  95      * may also dispose the stream. This does not close the stream. It
  96      * just marks it as not for further use by this service.
  97      */
  98     public void dispose() {
  99         disposed = true;
 100     }
 101 
 102     /**
 103      * Returns a {@code boolean} indicating whether or not
 104      * this {@code StreamPrintService} has been disposed.
 105      * If this object has been disposed, will return true.
 106      * Used by services and client applications to recognize streams
 107      * to which no further data should be written.
 108      * @return if this {@code StreamPrintService} has been disposed


 109      */
 110     public boolean isDisposed() {
 111         return disposed;
 112     }
 113 
 114 }
   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. StreamPrintService's are not
  48  * 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 }
< prev index next >