01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.utils;
07:
08: import java.io.IOException;
09: import java.io.Writer;
10:
11: /**
12: * A simple wrapper to present {@link IWriteable} interface for a regular <code>java.io.Writer</code>.
13: *
14: * @author Peter Kharchenko {@link <a href="mailto:pkharchenko@interactivebusiness.com"">pkharchenko@interactivebusiness.com"</a>}
15: * @version $Revision: 36690 $
16: */
17: public class WriteableWriterWrapper implements IWriteable {
18: protected final Writer out;
19:
20: public WriteableWriterWrapper(Writer out) {
21: this .out = out;
22: }
23:
24: public void write(int i) throws IOException {
25: out.write(i);
26: }
27:
28: public void flush() throws IOException {
29: out.flush();
30: }
31:
32: public void close() throws IOException {
33: out.close();
34: }
35:
36: public void write(int[] ibuf, int off, int len) throws IOException {
37: char[] cbuf = new char[len - off];
38: int j = 0;
39: for (int i = off; i < len; i++) {
40: cbuf[j++] = (char) ibuf[i];
41: }
42: if (j > 0) {
43: out.write(cbuf);
44: }
45: }
46:
47: public void write(int[] ibuf) throws IOException {
48: write(ibuf, 0, ibuf.length);
49: }
50: }
|