01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.util.transformers;
11:
12: import java.io.*;
13:
14: /**
15: * You need only to implement transform(Reader, Writer) you have the simplest
16: * kind of tranformer (which is 'streamable'). The name becoming your class name.
17: *
18: * @author Michiel Meeuwissen
19: * @since MMBase-1.7
20: */
21:
22: public abstract class ReaderTransformer implements CharTransformer {
23:
24: // javadoc inherited
25: public abstract Writer transform(Reader r, Writer w);
26:
27: // javadoc inherited
28: public Writer transformBack(Reader r, Writer w) {
29: throw new UnsupportedOperationException(
30: "transformBack is not supported for this transformer");
31: }
32:
33: // javadoc inherited
34: public final Writer transformBack(Reader r) {
35: return transformBack(r, new StringWriter());
36: }
37:
38: // javadoc inherited
39: public final Writer transform(Reader r) {
40: return transform(r, new StringWriter());
41: }
42:
43: // javadoc inherited
44: public String transform(String r) {
45: if (r == null)
46: return null;
47: Writer sw = transform(new StringReader(r));
48: return sw.toString();
49: }
50:
51: // javadoc inherited
52: public String transformBack(String r) {
53: if (r == null)
54: return null;
55: Writer sw = transformBack(new StringReader(r));
56: return sw.toString();
57: }
58: }
|