1111
1212class OutputStreamThread {
1313
14- private Client client ;
15- private Socket socket ;
16- private List <Packet > packets ;
17- private Timer timer ;
14+ private final Client client ;
15+ private final Socket socket ;
16+ private final List <Packet > packets ;
17+ private final Timer timer ;
1818
1919 {
2020 this .packets = new LinkedList <>();
@@ -31,46 +31,46 @@ public void run() {
3131 OutputStream outputStream = null ;
3232 try {
3333 outputStream = this .socket .getOutputStream ();
34- } catch (IOException e ) {
34+ } catch (final IOException e ) {
3535 e .printStackTrace ();
3636 }
37- OutputStream finalOutputStream = outputStream ;
37+ final OutputStream finalOutputStream = outputStream ;
3838 //start sending send byte arrays
3939 this .timer .scheduleAtFixedRate (new TimerTask () {
4040 @ Override
4141 public void run () {
4242 try {
43- if (socket .isClosed ()) {
43+ if (OutputStreamThread . this . socket .isClosed ()) {
4444 //interrupt thread
45- interrupt ();
45+ OutputStreamThread . this . interrupt ();
4646 return ;
4747 }
4848 //skip when no packets available to send
49- if (!packets .isEmpty ()) {
49+ if (!OutputStreamThread . this . packets .isEmpty ()) {
5050 //get next packet available to send
51- Packet packet = packets .get (0 );
51+ final Packet packet = OutputStreamThread . this . packets .get (0 );
5252 //check if packet is valid
5353 if (packet != null ) {
5454 //remove packet
55- packets .remove (0 );
56- WritingByteBuffer writingByteBuffer = new WritingByteBuffer ();
55+ OutputStreamThread . this . packets .remove (0 );
56+ final WritingByteBuffer writingByteBuffer = new WritingByteBuffer ();
5757 //check if packet is UpdateUUIDPacket
5858 if (packet .getClass ().equals (UpdateUUIDPacket .class )) {
5959 writingByteBuffer .writeInt (-2 );
6060 writingByteBuffer .writeUUID (packet .getConnectionUUID ());
6161 } else {
6262 //get packetId
63- int packetId = PacketRegistry .indexOf (packet .getClass ());
63+ final int packetId = PacketRegistry .indexOf (packet .getClass ());
6464 //write packetId
6565 writingByteBuffer .writeInt (packetId );
6666 //write connectionUuid
67- writingByteBuffer .writeUUID (client .getConnectionUUID ().get ());
67+ writingByteBuffer .writeUUID (OutputStreamThread . this . client .getConnectionUUID ().get ());
6868 //initialise packet
6969 packet .send (writingByteBuffer );
7070 }
7171 try {
7272 //receive bytes
73- byte [] bytes = writingByteBuffer .toBytes ();
73+ final byte [] bytes = writingByteBuffer .toBytes ();
7474 //check if outputstream is null
7575 assert finalOutputStream != null ;
7676 //write bytes length
@@ -79,14 +79,14 @@ public void run() {
7979 finalOutputStream .write (bytes );
8080 //flush outputStream
8181 finalOutputStream .flush ();
82- } catch (SocketException ignored ) {
82+ } catch (final SocketException ignored ) {
8383
8484 }
8585 }
8686 }
87- } catch (IOException e ) {
87+ } catch (final IOException e ) {
8888 e .printStackTrace ();
89- } catch (NullPointerException ignored ) {
89+ } catch (final NullPointerException ignored ) {
9090
9191 }
9292 }
@@ -97,7 +97,7 @@ public void interrupt() {
9797 this .timer .cancel ();
9898 }
9999
100- public void send (Packet packet ) {
100+ public void send (final Packet packet ) {
101101 this .packets .add (packet );
102102 }
103103}
0 commit comments