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
11 * @author Erik Brakkee
14 public class ForwarderThread extends Thread {
16 private String _prefix;
18 private Barrier _barrier;
20 private InputStream _is;
22 private OutputStream _os;
25 * Constructs the forwarder thread.
26 * @param aPrefix Prefix to use in the output.
27 * @param aBarrier Barrier to block on before actually closing the stream.
28 * This is done to make sure that connections are only closed in th e
29 * proxy when the forwarders in both directions are ready to close.
30 * @param aIs Input stream to read from.
31 * @param aOs Output stream to forward to.
33 public ForwarderThread( String aPrefix, Barrier aBarrier,
34 InputStream aIs, OutputStream aOs ) {
42 boolean firstChar = true;
50 System.out.print( _prefix );
53 System.out.print( (char) c );
57 } catch ( IOException e ) {
62 } catch ( IOException e ) {
71 private void closeStreams( ) {
72 _barrier.block( ); // wait until the other forwarder for the other direction
76 } catch ( IOException e1 ) {
82 } catch ( IOException e1 ) {
85 System.out.println(_prefix + " closed");