001: /**
002: * Copyright (c) 2003, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.examples;
031:
032: import java.io.IOException;
033: import java.io.InputStream;
034: import java.io.OutputStream;
035:
036: import org.pdfbox.cos.COSDocument;
037:
038: import org.pdfbox.pdmodel.PDDocument;
039:
040: import org.pdfbox.pdfwriter.COSWriter;
041:
042: /**
043: * A simple class which has some methods used by all examples.
044: *
045: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
046: * @version $Revision: 1.4 $
047: */
048: public abstract class AbstractExample {
049: /**
050: * Close the stream.
051: *
052: * @param stream The stream to close.
053: *
054: * @throws IOException If there is an error closing the stream.
055: */
056: public void close(InputStream stream) throws IOException {
057: if (stream != null) {
058: stream.close();
059: }
060: }
061:
062: /**
063: * Close the stream.
064: *
065: * @param stream The stream to close.
066: *
067: * @throws IOException If there is an error closing the stream.
068: */
069: public void close(OutputStream stream) throws IOException {
070: if (stream != null) {
071: stream.close();
072: }
073: }
074:
075: /**
076: * Close the document.
077: *
078: * @param doc The doc to close.
079: *
080: * @throws IOException If there is an error closing the document.
081: */
082: public void close(COSDocument doc) throws IOException {
083: if (doc != null) {
084: doc.close();
085: }
086: }
087:
088: /**
089: * Close the document.
090: *
091: * @param doc The doc to close.
092: *
093: * @throws IOException If there is an error closing the document.
094: */
095: public void close(PDDocument doc) throws IOException {
096: if (doc != null) {
097: doc.close();
098: }
099: }
100:
101: /**
102: * Close the writer.
103: *
104: * @param writer The writer to close.
105: *
106: * @throws IOException If there is an error closing the writer.
107: */
108: public static void close(COSWriter writer) throws IOException {
109: if (writer != null) {
110: writer.close();
111: }
112: }
113: }
|