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: import org.mmbase.util.logging.*;
14:
15: /**
16: * A Runnable implementation to perform a CharTransform between a Reader and a Writer. This is used
17: * in {@link ChainedCharTransformer}, {@link TransformingWriter} and {@link TransformingReader},
18: * because those need a thread for each step of the transformation.
19: *
20: * @author Michiel Meeuwissen
21: * @since MMBase-1.8
22: * @version $Id: CharTransformerLink.java,v 1.2 2005/01/30 16:46:37 nico Exp $
23: */
24:
25: public class CharTransformerLink implements Runnable {
26:
27: private static Logger log = Logging
28: .getLoggerInstance(CharTransformerLink.class);
29:
30: private CharTransformer charTransformer;
31: private Writer writer;
32: private Reader reader;
33: private boolean closeWriter;
34: private boolean ready = false;
35:
36: public CharTransformerLink(CharTransformer ct, Reader r, Writer w,
37: boolean cw) {
38: reader = r;
39: writer = w;
40: charTransformer = ct;
41: closeWriter = cw;
42: }
43:
44: synchronized public void run() {
45: try {
46: charTransformer.transform(reader, writer);
47: if (closeWriter) {
48: writer.close();
49: }
50: } catch (IOException io) {
51: log.error(io.toString());
52: log.error(io);
53: }
54: ready = true;
55: notifyAll();
56: }
57:
58: synchronized public boolean ready() {
59: return ready;
60: }
61: }
|