001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.io;
014:
015: import java.io.IOException;
016: import java.io.OutputStream;
017: import java.io.PrintStream;
018:
019: /**
020: * A Device encapsulating a ServletOutputStream
021: *
022: * @author <a href="mailto:hengels@to.com">Holger Engels</a>
023: */
024: public final class OutputStreamDevice implements Device {
025: private PrintStream out;
026:
027: public OutputStreamDevice(OutputStream out) {
028: this .out = new PrintStream(out);
029: }
030:
031: public boolean isSizePreserving() {
032: return true;
033: }
034:
035: /**
036: * Flush this Stream.
037: */
038: public void flush() throws IOException {
039: out.flush();
040: }
041:
042: public void close() throws IOException {
043: out.close();
044: }
045:
046: /**
047: * Print a String.
048: */
049: public Device print(String s) throws IOException {
050: if (s == null)
051: out.print("null");
052: else
053: out.print(s);
054: return this ;
055: }
056:
057: /**
058: * Print an integer.
059: */
060: public Device print(int i) throws IOException {
061: out.print(i);
062: return this ;
063: }
064:
065: /**
066: * Print any Object
067: */
068: public Device print(Object o) throws IOException {
069: if (o == null)
070: out.print("null");
071: else
072: out.print(o.toString());
073: return this ;
074: }
075:
076: /**
077: * Print a character.
078: */
079: public Device print(char c) throws IOException {
080: out.print(c);
081: return this ;
082: }
083:
084: /**
085: * Print an array of chars.
086: */
087: public Device print(char[] c) throws IOException {
088: return print(c, 0, c.length - 1);
089: }
090:
091: /**
092: * Print a character array.
093: */
094: public Device print(char[] c, int start, int len)
095: throws IOException {
096: final int end = start + len;
097: for (int i = start; i < end; ++i)
098: out.print(c[i]);
099: return this ;
100: }
101:
102: /**
103: * Writes the specified byte to this data output stream.
104: */
105: public Device write(int c) throws IOException {
106: out.write(c);
107: return this ;
108: }
109:
110: /**
111: * Writes b.length bytes from the specified byte array to this
112: * output stream.
113: */
114: public Device write(byte b[]) throws IOException {
115: out.write(b);
116: return this ;
117: }
118:
119: /**
120: * Writes len bytes from the specified byte array starting at offset
121: * off to this output stream.
122: */
123: public Device write(byte b[], int off, int len) throws IOException {
124: out.write(b, off, len);
125: return this;
126: }
127: }
|