11/*
2- * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//io/src/test/org/apache/commons/io/DemuxTestCase.java,v 1.7 2003/11/22 20:18:54 jeremias Exp $
3- * $Revision: 1.7 $
4- * $Date: 2003/11/22 20:18:54 $
2+ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//io/src/test/org/apache/commons/io/DemuxTestCase.java,v 1.8 2003/12/30 07:00:03 bayard Exp $
3+ * $Revision: 1.8 $
4+ * $Date: 2003/12/30 07:00:03 $
55 *
66 * ====================================================================
77 *
7979 *
8080 * @author <a href="mailto:peter@apache.org">Peter Donald</a>
8181 */
82- public final class DemuxTestCase
82+ public class DemuxTestCase
8383 extends TestCase
8484{
85- private static final String T1 = "Thread1" ;
86- private static final String T2 = "Thread2" ;
87- private static final String T3 = "Thread3" ;
88- private static final String T4 = "Thread4" ;
85+ private static String T1 = "Thread1" ;
86+ private static String T2 = "Thread2" ;
87+ private static String T3 = "Thread3" ;
88+ private static String T4 = "Thread4" ;
8989
90- private static final String DATA1 = "Data for thread1" ;
91- private static final String DATA2 = "Data for thread2" ;
92- private static final String DATA3 = "Data for thread3" ;
93- private static final String DATA4 = "Data for thread4" ;
90+ private static String DATA1 = "Data for thread1" ;
91+ private static String DATA2 = "Data for thread2" ;
92+ private static String DATA3 = "Data for thread3" ;
93+ private static String DATA4 = "Data for thread4" ;
9494
95- private static final Random c_random = new Random ();
96- private final HashMap m_outputMap = new HashMap ();
97- private final HashMap m_threadMap = new HashMap ();
95+ private static Random c_random = new Random ();
96+ private HashMap m_outputMap = new HashMap ();
97+ private HashMap m_threadMap = new HashMap ();
9898
99- public DemuxTestCase ( final String name )
99+ public DemuxTestCase ( String name )
100100 {
101101 super ( name );
102102 }
103103
104- private String getOutput ( final String threadName )
104+ private String getOutput ( String threadName )
105105 throws IOException
106106 {
107- final ByteArrayOutputStream output =
107+ ByteArrayOutputStream output =
108108 (ByteArrayOutputStream )m_outputMap .get ( threadName );
109109 assertNotNull ( "getOutput()" , output );
110110
111111 return output .toString ();
112112 }
113113
114- private String getInput ( final String threadName )
114+ private String getInput ( String threadName )
115115 throws IOException
116116 {
117- final ReaderThread thread = (ReaderThread )m_threadMap .get ( threadName );
117+ ReaderThread thread = (ReaderThread )m_threadMap .get ( threadName );
118118 assertNotNull ( "getInput()" , thread );
119119
120120 return thread .getData ();
@@ -123,53 +123,53 @@ private String getInput( final String threadName )
123123 private void doStart ()
124124 throws Exception
125125 {
126- final Iterator iterator = m_threadMap .keySet ().iterator ();
126+ Iterator iterator = m_threadMap .keySet ().iterator ();
127127 while ( iterator .hasNext () )
128128 {
129- final String name = (String )iterator .next ();
130- final Thread thread = (Thread )m_threadMap .get ( name );
129+ String name = (String )iterator .next ();
130+ Thread thread = (Thread )m_threadMap .get ( name );
131131 thread .start ();
132132 }
133133 }
134134
135135 private void doJoin ()
136136 throws Exception
137137 {
138- final Iterator iterator = m_threadMap .keySet ().iterator ();
138+ Iterator iterator = m_threadMap .keySet ().iterator ();
139139 while ( iterator .hasNext () )
140140 {
141- final String name = (String )iterator .next ();
142- final Thread thread = (Thread )m_threadMap .get ( name );
141+ String name = (String )iterator .next ();
142+ Thread thread = (Thread )m_threadMap .get ( name );
143143 thread .join ();
144144 }
145145 }
146146
147- private void startWriter ( final String name ,
148- final String data ,
149- final DemuxOutputStream demux )
147+ private void startWriter ( String name ,
148+ String data ,
149+ DemuxOutputStream demux )
150150 throws Exception
151151 {
152- final ByteArrayOutputStream output = new ByteArrayOutputStream ();
152+ ByteArrayOutputStream output = new ByteArrayOutputStream ();
153153 m_outputMap .put ( name , output );
154- final WriterThread thread =
154+ WriterThread thread =
155155 new WriterThread ( name , data , output , demux );
156156 m_threadMap .put ( name , thread );
157157 }
158158
159- private void startReader ( final String name ,
160- final String data ,
161- final DemuxInputStream demux )
159+ private void startReader ( String name ,
160+ String data ,
161+ DemuxInputStream demux )
162162 throws Exception
163163 {
164- final ByteArrayInputStream input = new ByteArrayInputStream ( data .getBytes () );
165- final ReaderThread thread = new ReaderThread ( name , input , demux );
164+ ByteArrayInputStream input = new ByteArrayInputStream ( data .getBytes () );
165+ ReaderThread thread = new ReaderThread ( name , input , demux );
166166 m_threadMap .put ( name , thread );
167167 }
168168
169169 public void testOutputStream ()
170170 throws Exception
171171 {
172- final DemuxOutputStream output = new DemuxOutputStream ();
172+ DemuxOutputStream output = new DemuxOutputStream ();
173173 startWriter ( T1 , DATA1 , output );
174174 startWriter ( T2 , DATA2 , output );
175175 startWriter ( T3 , DATA3 , output );
@@ -187,7 +187,7 @@ public void testOutputStream()
187187 public void testInputStream ()
188188 throws Exception
189189 {
190- final DemuxInputStream input = new DemuxInputStream ();
190+ DemuxInputStream input = new DemuxInputStream ();
191191 startReader ( T1 , DATA1 , input );
192192 startReader ( T2 , DATA2 , input );
193193 startReader ( T3 , DATA3 , input );
@@ -205,13 +205,13 @@ public void testInputStream()
205205 private static class ReaderThread
206206 extends Thread
207207 {
208- private final StringBuffer m_buffer = new StringBuffer ();
209- private final InputStream m_input ;
210- private final DemuxInputStream m_demux ;
208+ private StringBuffer m_buffer = new StringBuffer ();
209+ private InputStream m_input ;
210+ private DemuxInputStream m_demux ;
211211
212- ReaderThread ( final String name ,
213- final InputStream input ,
214- final DemuxInputStream demux )
212+ ReaderThread ( String name ,
213+ InputStream input ,
214+ DemuxInputStream demux )
215215 {
216216 super ( name );
217217 m_input = input ;
@@ -235,12 +235,12 @@ public void run()
235235 //System.out.println( "Reading: " + (char)ch );
236236 m_buffer .append ( (char )ch );
237237
238- final int sleepTime = Math .abs ( c_random .nextInt () % 10 );
238+ int sleepTime = Math .abs ( c_random .nextInt () % 10 );
239239 Thread .sleep ( sleepTime );
240240 ch = m_demux .read ();
241241 }
242242 }
243- catch ( final Exception e )
243+ catch ( Exception e )
244244 {
245245 e .printStackTrace ();
246246 }
@@ -250,14 +250,14 @@ public void run()
250250 private static class WriterThread
251251 extends Thread
252252 {
253- private final byte [] m_data ;
254- private final OutputStream m_output ;
255- private final DemuxOutputStream m_demux ;
253+ private byte [] m_data ;
254+ private OutputStream m_output ;
255+ private DemuxOutputStream m_demux ;
256256
257- WriterThread ( final String name ,
258- final String data ,
259- final OutputStream output ,
260- final DemuxOutputStream demux )
257+ WriterThread ( String name ,
258+ String data ,
259+ OutputStream output ,
260+ DemuxOutputStream demux )
261261 {
262262 super ( name );
263263 m_output = output ;
@@ -274,10 +274,10 @@ public void run()
274274 {
275275 //System.out.println( "Writing: " + (char)m_data[ i ] );
276276 m_demux .write ( m_data [ i ] );
277- final int sleepTime = Math .abs ( c_random .nextInt () % 10 );
277+ int sleepTime = Math .abs ( c_random .nextInt () % 10 );
278278 Thread .sleep ( sleepTime );
279279 }
280- catch ( final Exception e )
280+ catch ( Exception e )
281281 {
282282 e .printStackTrace ();
283283 }
0 commit comments