create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / gui / print / PDFPrintStreamDoc.java
1 /*
2  * PDFPrintStreamDoc.java
3  */
4 package net.sf.openrocket.gui.print;
5
6 import javax.print.Doc;
7 import javax.print.DocFlavor;
8 import javax.print.attribute.AttributeSetUtilities;
9 import javax.print.attribute.DocAttributeSet;
10 import java.io.*;
11
12 /**
13  * This class implements a javax Doc specifically for PDF printing. All reports in OpenRocket are PDF (iText) based.
14  */
15 public class PDFPrintStreamDoc implements Doc {
16
17     /** The source stream of the PDF document. */
18     private InputStream stream;
19
20     /** The document's attributes. */
21     private DocAttributeSet attributeSet;
22
23     /**
24      * Constructor.
25      *
26      * @param ostream  an output stream representing the pdf doc
27      * @param attributes the attributes of the document
28      */
29     public PDFPrintStreamDoc (ByteArrayOutputStream ostream, DocAttributeSet attributes) {
30         stream = new ByteArrayInputStream(ostream.toByteArray());
31         if (attributes != null) {
32             attributeSet = AttributeSetUtilities.unmodifiableView(attributes);
33         }
34     }
35
36     /**
37      * Flavor is PDF.
38      *
39      * @return PDF flavor
40      */
41     @Override
42     public DocFlavor getDocFlavor () {
43         return DocFlavor.INPUT_STREAM.PDF;
44     }
45
46     @Override
47     public DocAttributeSet getAttributes () {
48         return attributeSet;
49     }
50
51     /* Since the data is to be supplied as an InputStream delegate to
52      * getStreamForBytes().
53      */
54     @Override
55     public Object getPrintData () throws IOException {
56         return getStreamForBytes();
57     }
58
59     /**
60      * Intentionally null since the flavor is PDF.
61      *
62      * @return null
63      */
64     @Override
65     public Reader getReaderForText () {
66         return null;
67     }
68
69     /* Return the print data as an InputStream.
70      * Always return the same instance.
71      */
72     @Override
73     public InputStream getStreamForBytes () throws IOException {
74         return stream;
75     }
76 }