~sword-devel/jsword/trunk

« back to all changes in this revision

Viewing changes to jsword/java/historic/org/crosswire/io/ConnectedReader.java

  • Committer: joe
  • Date: 2002-10-08 21:36:18 UTC
  • Revision ID: svn-v4:a88caf3b-7e0a-0410-8d0d-cecb45342206:trunk:80
big config and comment update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
package org.crosswire.io;
3
 
 
4
 
import java.io.*;
5
 
 
6
 
/**
7
 
 * ConnectedReader is for use in command line processing type applications
8
 
 * where it is important to flush and output to the user beofre we ask for
9
 
 * some input. This is a simplar concept to the C++ tie() method in the
10
 
 * iostreams classes.
11
 
 * @author Joe Walker
12
 
 */
13
 
public class ConnectedReader extends Reader
14
 
{
15
 
    /**
16
 
     *
17
 
     */
18
 
    public ConnectedReader(Reader in)
19
 
    {
20
 
        this.in = in;
21
 
    }
22
 
 
23
 
    /**
24
 
     *
25
 
     */
26
 
    public void tie(Writer out)
27
 
    {
28
 
        this.out = out;
29
 
    }
30
 
 
31
 
    /**
32
 
     * Override to pass out to the current Stream.
33
 
     * @return The byte read, as normal.
34
 
     */
35
 
    public int read() throws IOException
36
 
    {
37
 
        if (out != null)
38
 
            out.flush();
39
 
 
40
 
        return in.read();
41
 
    }
42
 
 
43
 
    /**
44
 
     * Override to pass out to the current Stream.
45
 
     * @return The byte read, as normal.
46
 
     */
47
 
    public int read(char[] cbuf, int off, int len) throws IOException
48
 
    {
49
 
        if (out != null)
50
 
            out.flush();
51
 
 
52
 
        return in.read(cbuf, off, len);
53
 
    }
54
 
 
55
 
    /**
56
 
     * Shutdown
57
 
     */
58
 
    public void close() throws IOException
59
 
    {
60
 
        in.close();
61
 
    }
62
 
 
63
 
    private Writer out = null;
64
 
    private Reader in = null;
65
 
}