1 package org.wamblee.socketproxy;
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.OutputStream;
8 * Forwarder thread which handles forwarding of an input stream to
12 public class ForwarderThread extends Thread {
14 private String _prefix;
16 private Barrier _barrier;
18 private InputStream _is;
20 private OutputStream _os;
23 * Constructs the forwarder thread.
24 * @param aPrefix Prefix to use in the output.
25 * @param aBarrier Barrier to block on before actually closing the stream.
26 * This is done to make sure that connections are only closed in th e
27 * proxy when the forwarders in both directions are ready to close.
28 * @param aIs Input stream to read from.
29 * @param aOs Output stream to forward to.
31 public ForwarderThread( String aPrefix, Barrier aBarrier,
32 InputStream aIs, OutputStream aOs ) {
40 boolean firstChar = true;
48 System.out.print( _prefix );
51 System.out.print( (char) c );
55 } catch ( IOException e ) {
60 } catch ( IOException e ) {
69 private void closeStreams( ) {
70 _barrier.block( ); // wait until the other forwarder for the other direction
74 } catch ( IOException e1 ) {
80 } catch ( IOException e1 ) {
83 System.out.println(_prefix + " closed");