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</code> class is 41 * obtained from a {@link StreamPrintServiceFactory} instance. 42 * <p> 43 * Note that a <code>StreamPrintService</code> is different from a 44 * <code>PrintService</code>, which supports a 45 * {@link javax.print.attribute.standard.Destination Destination} 46 * attribute. A <code>StreamPrintService</code> always requires an output 47 * stream, whereas a <code>PrintService</code> optionally accepts a 48 * <code>Destination</code>. A <code>StreamPrintService</code> 49 * has no default destination for its formatted output. 50 * Additionally a <code>StreamPrintService</code> 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</code>. 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</code> indicating whether or not 104 * this <code>StreamPrintService</code> 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</code> has been disposed 109 */ 110 public boolean isDisposed() { 111 return disposed; 112 } 113 114 } | 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 } |