|
5 | 5 | import java.net.Socket; |
6 | 6 | import java.net.SocketException; |
7 | 7 | import java.util.LinkedList; |
8 | | -import java.util.List; |
9 | 8 | import java.util.Timer; |
10 | 9 | import java.util.TimerTask; |
11 | 10 |
|
12 | 11 | class OutputStreamThread { |
13 | 12 |
|
14 | 13 | private final Client client; |
15 | 14 | private final Socket socket; |
16 | | - private final List<Packet> packets; |
17 | | - private final Timer timer; |
18 | | - |
19 | | - { |
20 | | - this.packets = new LinkedList<>(); |
21 | | - this.timer = new Timer(); |
22 | | - } |
| 15 | + private final LinkedList<Packet> packets = new LinkedList<>(); |
| 16 | + private final Timer timer = new Timer(); |
23 | 17 |
|
24 | 18 | public OutputStreamThread(final Client client) { |
25 | 19 | this.client = client; |
26 | 20 | this.socket = this.client.getSocket(); |
27 | 21 | } |
28 | 22 |
|
29 | | - public void run() { |
| 23 | + public void run() throws IOException { |
30 | 24 | //initialise outputStream |
31 | | - OutputStream outputStream = null; |
32 | | - try { |
33 | | - outputStream = this.socket.getOutputStream(); |
34 | | - } catch (final IOException e) { |
35 | | - e.printStackTrace(); |
36 | | - } |
37 | | - final OutputStream finalOutputStream = outputStream; |
| 25 | + final OutputStream finalOutputStream = this.socket.getOutputStream(); |
38 | 26 | //start sending send byte arrays |
39 | 27 | this.timer.scheduleAtFixedRate(new TimerTask() { |
40 | 28 | @Override |
@@ -79,15 +67,13 @@ public void run() { |
79 | 67 | finalOutputStream.write(bytes); |
80 | 68 | //flush outputStream |
81 | 69 | finalOutputStream.flush(); |
82 | | - } catch (final SocketException ignored) { |
83 | | - |
| 70 | + } catch (final SocketException exception) { |
| 71 | + exception.printStackTrace(); |
84 | 72 | } |
85 | 73 | } |
86 | 74 | } |
87 | | - } catch (final IOException e) { |
88 | | - e.printStackTrace(); |
89 | | - } catch (final NullPointerException ignored) { |
90 | | - |
| 75 | + } catch (final IOException | NullPointerException exception) { |
| 76 | + exception.printStackTrace(); |
91 | 77 | } |
92 | 78 | } |
93 | 79 | }, 0, 1); |
|
0 commit comments