KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > io > ServletDevice


1 /*
2  * $Id: ServletDevice.java,v 1.3 2004/12/01 07:54:08 hengels Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.io;
15
16 import javax.servlet.ServletOutputStream JavaDoc;
17 import java.io.IOException JavaDoc;
18
19 /**
20  * A Device encapsulating a ServletOutputStream.
21  *
22  * @author <a HREF="mailto:H.Zeller@acm.org">Henner Zeller</a>
23  * @version $Revision: 1.3 $
24  */

25 public final class ServletDevice implements Device {
26     private ServletOutputStream JavaDoc out;
27
28
29     public ServletDevice(ServletOutputStream JavaDoc out) {
30         this.out = out;
31     }
32
33     public boolean isSizePreserving() { return true; }
34
35     /**
36      * Flush this Stream.
37      */

38     public void flush() throws IOException JavaDoc {
39         out.flush();
40     }
41
42     public void close() throws IOException JavaDoc {
43         out.close();
44     }
45
46     /**
47      * Print a String.
48      */

49     public Device print(String JavaDoc s) throws IOException JavaDoc {
50         if (s == null)
51             out.print("null");
52         else
53             out.print(s);
54         return this;
55     }
56
57     /**
58      * Print an integer.
59      */

60     public Device print(int i) throws IOException JavaDoc {
61         out.print(i);
62         return this;
63     }
64
65     /**
66      * Print any Object
67      */

68     public Device print(Object JavaDoc o) throws IOException JavaDoc {
69         if (o == null)
70             out.print("null");
71         else
72             out.print(o.toString());
73         return this;
74     }
75
76     /**
77      * Print a character.
78      */

79     public Device print(char c) throws IOException JavaDoc {
80         out.print(c);
81         return this;
82     }
83
84     /**
85      * Print an array of chars.
86      */

87     public Device print(char[] c) throws IOException JavaDoc {
88         return print(c, 0, c.length - 1);
89     }
90
91     /**
92      * Print a character array.
93      */

94     public Device print(char[] c, int start, int len) throws IOException JavaDoc {
95         final int end = start + len;
96         for (int i = start; i < end; ++i)
97             out.print(c[i]);
98         return this;
99     }
100
101     /**
102      * Writes the specified byte to this data output stream.
103      */

104     public Device write(int c) throws IOException JavaDoc {
105         out.write(c);
106         return this;
107     }
108
109     /**
110      * Writes b.length bytes from the specified byte array to this
111      * output stream.
112      */

113     public Device write(byte b[]) throws IOException JavaDoc {
114         out.write(b);
115         return this;
116     }
117
118     /**
119      * Writes len bytes from the specified byte array starting at offset
120      * off to this output stream.
121      */

122     public Device write(byte b[], int off, int len) throws IOException JavaDoc {
123         out.write(b, off, len);
124         return this;
125     }
126 }
127
128
129
Popular Tags