File tree Expand file tree Collapse file tree 7 files changed +7
-29
lines changed
main/java/com/github/dddpaul/netcat
test/java/com/github/dddpaul/netcat Expand file tree Collapse file tree 7 files changed +7
-29
lines changed Original file line number Diff line number Diff line change @@ -16,19 +16,11 @@ public class NetCat implements NetCater
16
16
protected InputStream input ;
17
17
protected OutputStream output ;
18
18
19
- public NetCat () {}
20
-
21
19
public NetCat ( NetCatListener listener )
22
20
{
23
21
this .listener = listener ;
24
22
}
25
23
26
- @ Override
27
- public void setListener ( NetCatListener listener )
28
- {
29
- this .listener = listener ;
30
- }
31
-
32
24
@ Override
33
25
public void setInput ( InputStream input )
34
26
{
Original file line number Diff line number Diff line change @@ -17,7 +17,6 @@ enum Proto { TCP, UDP }
17
17
public void cancel ();
18
18
public void execute ( String ... params );
19
19
public void executeParallel ( String ... params );
20
- public void setListener ( NetCatListener listener );
21
20
public void setInput ( InputStream input );
22
21
public void createOutput ();
23
22
public void closeOutput ();
Original file line number Diff line number Diff line change @@ -25,11 +25,6 @@ public class TcpNetCat extends NetCat
25
25
private ServerSocketChannel serverChannel ;
26
26
private Socket socket ;
27
27
28
- public TcpNetCat ()
29
- {
30
- super ();
31
- }
32
-
33
28
public TcpNetCat ( NetCatListener listener )
34
29
{
35
30
super ( listener );
Original file line number Diff line number Diff line change @@ -23,11 +23,6 @@ public UdpNetCat( NetCatListener listener )
23
23
super ( listener );
24
24
}
25
25
26
- public UdpNetCat ()
27
- {
28
- super ();
29
- }
30
-
31
26
@ Override
32
27
public void cancel ()
33
28
{
Original file line number Diff line number Diff line change 3
3
import android .os .Bundle ;
4
4
import android .support .v4 .app .Fragment ;
5
5
6
+ import com .github .dddpaul .netcat .NetCatListener ;
6
7
import com .github .dddpaul .netcat .NetCater ;
7
8
import com .github .dddpaul .netcat .TcpNetCat ;
8
9
import com .github .dddpaul .netcat .UdpNetCat ;
@@ -34,19 +35,19 @@ public NetCater getNetCat()
34
35
return netCat ;
35
36
}
36
37
37
- public NetCater getOrCreateNetCat ( Proto proto )
38
+ public NetCater getOrCreateNetCat ( Proto proto , NetCatListener listener )
38
39
{
39
40
switch ( proto ) {
40
41
case TCP :
41
42
if ( netCat != null && netCat instanceof TcpNetCat ) {
42
43
return netCat ;
43
44
}
44
- return new TcpNetCat ();
45
+ return new TcpNetCat ( listener );
45
46
case UDP :
46
47
if ( netCat != null && netCat instanceof UdpNetCat ) {
47
48
return netCat ;
48
49
}
49
- return new UdpNetCat ();
50
+ return new UdpNetCat ( listener );
50
51
}
51
52
return null ;
52
53
}
Original file line number Diff line number Diff line change @@ -108,7 +108,6 @@ public void onResume()
108
108
netCatFragment = (NetCatFragment ) getFragmentManager ().findFragmentByTag ( NETCAT_FRAGMENT_TAG );
109
109
if ( netCatFragment != null ) {
110
110
netCat = netCatFragment .getNetCat ();
111
- netCat .setListener ( this );
112
111
}
113
112
}
114
113
@@ -203,8 +202,7 @@ public void connect( String connectTo )
203
202
return ;
204
203
}
205
204
String [] tokens = connectTo .split ( ":" );
206
- netCat = netCatFragment .getOrCreateNetCat ( Proto .valueOf ( tokens [0 ] ) );
207
- netCat .setListener ( this );
205
+ netCat = netCatFragment .getOrCreateNetCat ( Proto .valueOf ( tokens [0 ] ), this );
208
206
netCat .execute ( CONNECT .toString (), tokens [1 ], tokens [2 ] );
209
207
}
210
208
@@ -219,8 +217,7 @@ public void listen( String listenOn )
219
217
return ;
220
218
}
221
219
String [] tokens = listenOn .split ( ":" );
222
- netCat = netCatFragment .getOrCreateNetCat ( Proto .valueOf ( tokens [0 ] ) );
223
- netCat .setListener ( this );
220
+ netCat = netCatFragment .getOrCreateNetCat ( Proto .valueOf ( tokens [0 ] ), this );
224
221
netCat .execute ( LISTEN .toString (), tokens [1 ] );
225
222
}
226
223
Original file line number Diff line number Diff line change 20
20
import static com .github .dddpaul .netcat .NetCater .*;
21
21
import static com .github .dddpaul .netcat .NetCater .Op .CONNECT ;
22
22
import static com .github .dddpaul .netcat .NetCater .Op .LISTEN ;
23
- import static com .github .dddpaul .netcat .NetCater .Proto .*;
24
23
import static org .fest .assertions .api .ANDROID .assertThat ;
25
24
import static org .hamcrest .core .Is .is ;
26
25
import static org .junit .Assert .assertThat ;
@@ -52,7 +51,7 @@ public void setUp()
52
51
{
53
52
MockitoAnnotations .initMocks ( this );
54
53
when ( netCatFragmentMock .getNetCat () ).thenReturn ( netCatMock );
55
- when ( netCatFragmentMock .getOrCreateNetCat ( any ( Proto .class ) ) ).thenReturn ( netCatMock );
54
+ when ( netCatFragmentMock .getOrCreateNetCat ( any ( Proto .class ), any ( NetCatListener . class ) ) ).thenReturn ( netCatMock );
56
55
fragment = new ResultFragment ();
57
56
}
58
57
You can’t perform that action at this time.
0 commit comments