001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixcore.webservice.utils;
021:
022: import java.io.CharArrayWriter;
023: import java.io.IOException;
024: import java.io.Reader;
025: import java.nio.CharBuffer;
026:
027: /**
028: * @author mleidig@schlund.de
029: */
030: public class RecordingReader extends Reader {
031:
032: CharArrayWriter chars;
033: Reader reader;
034:
035: public RecordingReader(Reader reader) {
036: this .reader = reader;
037: chars = new CharArrayWriter();
038: }
039:
040: public char[] getCharacters() {
041: return chars.toCharArray();
042: }
043:
044: public void close() throws IOException {
045: reader.close();
046: }
047:
048: public void mark(int readAheadLimit) throws IOException {
049: //Not supported
050: }
051:
052: public boolean markSupported() {
053: return false;
054: }
055:
056: public int read() throws IOException {
057: int ch = reader.read();
058: if (ch != -1)
059: chars.write(ch);
060: return ch;
061: }
062:
063: public int read(char[] cbuf, int off, int len) throws IOException {
064: return reader.read(cbuf, off, len);
065: }
066:
067: public int read(char[] cbuf) throws IOException {
068: int no = reader.read(cbuf);
069: if (no != -1)
070: chars.write(cbuf, 0, no);
071: return no;
072: }
073:
074: public int read(CharBuffer target) throws IOException {
075: int oldPos = target.position();
076: int no = reader.read(target);
077: if (no > -1) {
078: char[] c = new char[no];
079: int newPos = target.position();
080: target.position(oldPos);
081: for (int i = 0; i < no; i++)
082: c[i] = target.charAt(i);
083: chars.write(c);
084: target.position(newPos);
085: }
086: return no;
087: }
088:
089: public boolean ready() throws IOException {
090: return reader.ready();
091: }
092:
093: public void reset() throws IOException {
094: reader.reset();
095: }
096:
097: public long skip(long n) throws IOException {
098: return reader.skip(n);
099: }
100:
101: }
|