2 * ConnectionInput - reads from the socket and writes data to the pipe.
4 * @version 1.00 - 20010418.
6 * Copyright (C) 2001 Ian Norton.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public Licence as published by
10 * the Free Software Foundation; either version 2 of the Licence, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public Licence for more details.
18 * You should have received a copy of the GNU General Public Licence
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Contacting the author :
24 * i.norton@lancaster.ac.uk
25 * http://www.lancs.ac.uk/~norton/
31 class ConnectionInput implements Runnable
34 public static final boolean DEBUG = false ;
37 private InputStream is ;
38 private PipedOutputStream pos ;
40 // Connection object that created us.
41 private Connection connection ;
44 private boolean disconnected ;
46 // Thread to run the read code in.
50 public static final String encoding = "latin1"; // "ISO8859_1";
54 * @param InputStream - InputStream from the socket to read from
55 * @param PipedOutputStream - Write the data out to here
56 * @param Connection - the object that created us
58 public ConnectionInput(PipedOutputStream p, Connection c)
60 // Initialise the streams & connection
68 * disconnect - disconnect the current connection.
70 public void disconnect()
74 if(DEBUG) System.out.println("ConnectionInput: disconnect()") ;
77 catch(IOException ex) { }
80 connection.disconnect() ;
85 * start - begin reading. Called when a connect has been achieved.
87 public void start(InputStream i)
91 disconnected = false ;
93 // Initialise the thread to read data & start it.
94 t = new Thread(this, "ConnectionInput") ;
103 byte[] b = new byte[16];
105 // Loop reading data.
110 // Read from InputStream and write to PipedOutputStream
116 String output = new String(b, 0, n, encoding) ;
124 catch(IOException ex)
129 System.out.println("ConnectionInput: IOException reading data.") ;
137 * @param String s - string to send to destination stream.
139 private void send(String s)
143 // Write the data to the stream.
144 for(int i=0;i<s.length();i++)
146 pos.write(s.charAt(i)) ;
150 catch(IOException ex)
152 System.out.println("ConnectionInput: IOException writing to multiplexor.") ;
155 } // End of send(String s)