1. /*
  2. * @(#)StreamPrintService.java 1.7 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.print;
  8. import java.io.OutputStream;
  9. /**
  10. * This class extends {@link PrintService} and represents a
  11. * print service that prints data in different formats to a
  12. * client-provided output stream.
  13. * This is principally intended for services where
  14. * the output format is a document type suitable for viewing
  15. * or archiving.
  16. * The output format must be declared as a mime type.
  17. * This is equivalent to an output document flavor where the
  18. * representation class is always "java.io.OutputStream"
  19. * An instance of the <code>StreamPrintService</code> class is
  20. * obtained from a {@link StreamPrintServiceFactory} instance.
  21. * <p>
  22. * Note that a <code>StreamPrintService</code> is different from a
  23. * <code>PrintService</code>, which supports a
  24. * {@link javax.print.attribute.standard.Destination Destination}
  25. * attribute. A <code>StreamPrintService</code> always requires an output
  26. * stream, whereas a <code>PrintService</code> optionally accepts a
  27. * <code>Destination</code>. A <code>StreamPrintService</code>
  28. * has no default destination for its formatted output.
  29. * Additionally a <code>StreamPrintService</code> is expected to generate
  30. output in
  31. * a format useful in other contexts.
  32. * StreamPrintService's are not expected to support the Destination attribute.
  33. */
  34. public abstract class StreamPrintService implements PrintService {
  35. private OutputStream outStream;
  36. private boolean disposed = false;
  37. private StreamPrintService() {
  38. };
  39. /**
  40. * Constructs a StreamPrintService object.
  41. *
  42. * @param out stream to which to send formatted print data.
  43. */
  44. protected StreamPrintService(OutputStream out) {
  45. this.outStream = out;
  46. }
  47. /**
  48. * Gets the output stream.
  49. *
  50. * @return the stream to which this service will send formatted print data.
  51. */
  52. public OutputStream getOutputStream() {
  53. return outStream;
  54. }
  55. /**
  56. * Returns the document format emitted by this print service.
  57. * Must be in mimetype format, compatible with the mime type
  58. * components of DocFlavors @see DocFlavor.
  59. * @return mime type identifying the output format.
  60. */
  61. public abstract String getOutputFormat();
  62. /**
  63. * Disposes this <code>StreamPrintService</code>.
  64. * If a stream service cannot be re-used, it must be disposed
  65. * to indicate this. Typically the client will call this method.
  66. * Services which write data which cannot meaningfully be appended to
  67. * may also dispose the stream. This does not close the stream. It
  68. * just marks it as not for further use by this service.
  69. */
  70. public void dispose() {
  71. disposed = true;
  72. }
  73. /**
  74. * Returns a <code>boolean</code> indicating whether or not
  75. * this <code>StreamPrintService</code> has been disposed.
  76. * If this object has been disposed, will return true.
  77. * Used by services and client applications to recognize streams
  78. * to which no further data should be written.
  79. * @return if this <code>StreamPrintService</code> has been disposed
  80. */
  81. public boolean isDisposed() {
  82. return disposed;
  83. }
  84. }