4343 * @usage Application
4444 * @see_external LIB_net/clientEvent
4545 */
46+ @ SuppressWarnings ("unused" )
4647public class Client implements Runnable {
4748
4849 protected static final int MAX_BUFFER_SIZE = 1 << 27 ; // 128 MB
@@ -61,7 +62,7 @@ public class Client implements Runnable {
6162
6263 final Object bufferLock = new Object [0 ];
6364
64- byte buffer [] = new byte [32768 ];
65+ byte [] buffer = new byte [32768 ];
6566 int bufferIndex ;
6667 int bufferLast ;
6768
@@ -96,14 +97,14 @@ public Client(PApplet parent, String host, int port) {
9697 clientEventMethod =
9798 parent .getClass ().getMethod ("clientEvent" , Client .class );
9899 } catch (Exception e ) {
99- // no such method, or an error.. which is fine, just ignore
100+ // no such method, or an error... which is fine, just ignore
100101 }
101102 // do the same for disconnectEvent(Client c);
102103 try {
103104 disconnectEventMethod =
104105 parent .getClass ().getMethod ("disconnectEvent" , Client .class );
105106 } catch (Exception e ) {
106- // no such method, or an error.. which is fine, just ignore
107+ // no such method, or an error... which is fine, just ignore
107108 }
108109
109110 } catch (IOException e ) {
@@ -115,7 +116,6 @@ public Client(PApplet parent, String host, int port) {
115116
116117 /**
117118 * @param socket any object of type Socket
118- * @throws IOException
119119 */
120120 public Client (PApplet parent , Socket socket ) throws IOException {
121121 this .parent = parent ;
@@ -134,14 +134,14 @@ public Client(PApplet parent, Socket socket) throws IOException {
134134 clientEventMethod =
135135 parent .getClass ().getMethod ("clientEvent" , Client .class );
136136 } catch (Exception e ) {
137- // no such method, or an error.. which is fine, just ignore
137+ // no such method, or an error... which is fine, just ignore
138138 }
139139 // do the same for disconnectEvent(Client c);
140140 try {
141141 disconnectEventMethod =
142142 parent .getClass ().getMethod ("disconnectEvent" , Client .class );
143143 } catch (Exception e ) {
144- // no such method, or an error.. which is fine, just ignore
144+ // no such method, or an error... which is fine, just ignore
145145 }
146146 }
147147
@@ -368,7 +368,7 @@ public void clear() {
368368 *
369369 * Returns a number between 0 and 255 for the next byte that's waiting in
370370 * the buffer. Returns -1 if there is no byte, although this should be
371- * avoided by first cheacking <b>available()</b> to see if any data is available.
371+ * avoided by first checking <b>available()</b> to see if any data is available.
372372 *
373373 * @webref client
374374 * @usage application
@@ -430,7 +430,7 @@ public byte[] readBytes() {
430430 if (bufferIndex == bufferLast ) return null ;
431431
432432 int length = bufferLast - bufferIndex ;
433- byte outgoing [] = new byte [length ];
433+ byte [] outgoing = new byte [length ];
434434 System .arraycopy (buffer , bufferIndex , outgoing , 0 , length );
435435
436436 bufferIndex = 0 ; // rewind
@@ -456,7 +456,7 @@ public byte[] readBytes(int max) {
456456
457457 int length = bufferLast - bufferIndex ;
458458 if (length > max ) length = max ;
459- byte outgoing [] = new byte [length ];
459+ byte [] outgoing = new byte [length ];
460460 System .arraycopy (buffer , bufferIndex , outgoing , 0 , length );
461461
462462 bufferIndex += length ;
@@ -482,7 +482,7 @@ public byte[] readBytes(int max) {
482482 *
483483 * @param bytebuffer passed in byte array to be altered
484484 */
485- public int readBytes (byte bytebuffer [] ) {
485+ public int readBytes (byte [] bytebuffer ) {
486486 synchronized (bufferLock ) {
487487 if (bufferIndex == bufferLast ) return 0 ;
488488
@@ -534,7 +534,7 @@ public byte[] readBytesUntil(int interesting) {
534534 if (found == -1 ) return null ;
535535
536536 int length = found - bufferIndex + 1 ;
537- byte outgoing [] = new byte [length ];
537+ byte [] outgoing = new byte [length ];
538538 System .arraycopy (buffer , bufferIndex , outgoing , 0 , length );
539539
540540 bufferIndex += length ;
@@ -560,7 +560,7 @@ public byte[] readBytesUntil(int interesting) {
560560 *
561561 * @param byteBuffer passed in byte array to be altered
562562 */
563- public int readBytesUntil (int interesting , byte byteBuffer [] ) {
563+ public int readBytesUntil (int interesting , byte [] byteBuffer ) {
564564 byte what = (byte )interesting ;
565565
566566 synchronized (bufferLock ) {
@@ -596,7 +596,7 @@ public int readBytesUntil(int interesting, byte byteBuffer[]) {
596596
597597
598598 /**
599- *
599+ *
600600 * Returns the all the data from the buffer as a <b>String</b>.
601601 *
602602 * In 4.0 beta 3, changed to using UTF-8 as the encoding,
@@ -607,8 +607,10 @@ public int readBytesUntil(int interesting, byte byteBuffer[]) {
607607 * @webBrief Returns the buffer as a <b>String</b>
608608 */
609609 public String readString () {
610- byte b [] = readBytes ();
611- if (b == null ) return null ;
610+ byte [] b = readBytes ();
611+ if (b == null ) {
612+ return null ;
613+ }
612614 return new String (b , StandardCharsets .UTF_8 );
613615 }
614616
@@ -628,15 +630,17 @@ public String readString() {
628630 * @param interesting character designated to mark the end of the data
629631 */
630632 public String readStringUntil (int interesting ) {
631- byte b [] = readBytesUntil (interesting );
632- if (b == null ) return null ;
633+ byte [] b = readBytesUntil (interesting );
634+ if (b == null ) {
635+ return null ;
636+ }
633637 return new String (b , StandardCharsets .UTF_8 );
634638 }
635639
636640
637641 /**
638- *
639- * Writes data to a server specified when constructing the client, or writes
642+ *
643+ * Writes data to a server specified when constructing the client, or writes
640644 * data to the specific client obtained from the Server <b>available()</b>
641645 * method.
642646 *
@@ -650,26 +654,19 @@ public void write(int data) { // will also cover char
650654 output .write (data & 0xff ); // for good measure do the &
651655 output .flush (); // hmm, not sure if a good idea
652656
653- } catch (Exception e ) { // null pointer or serial port dead
654- //errorMessage("write", e);
655- //e.printStackTrace();
656- //dispose();
657- //disconnect(e);
657+ } catch (Exception e ) { // null pointer or serial port dead
658658 e .printStackTrace ();
659659 stop ();
660660 }
661661 }
662662
663663
664- public void write (byte data [] ) {
664+ public void write (byte [] data ) {
665665 try {
666666 output .write (data );
667667 output .flush (); // hmm, not sure if a good idea
668668
669- } catch (Exception e ) { // null pointer or serial port dead
670- //errorMessage("write", e);
671- //e.printStackTrace();
672- //disconnect(e);
669+ } catch (Exception e ) { // null pointer or serial port dead
673670 e .printStackTrace ();
674671 stop ();
675672 }
@@ -683,27 +680,4 @@ public void write(byte data[]) {
683680 public void write (String data ) {
684681 write (data .getBytes (StandardCharsets .UTF_8 ));
685682 }
686-
687-
688- /**
689- * Handle disconnect due to an Exception being thrown.
690- */
691- /*
692- protected void disconnect(Exception e) {
693- dispose();
694- if (e != null) {
695- e.printStackTrace();
696- }
697- }
698- */
699-
700-
701- /**
702- * General error reporting, all corralled here just in case
703- * I think of something slightly more intelligent to do.
704- */
705- //public void errorMessage(String where, Exception e) {
706- //parent.die("Error inside Client." + where + "()", e);
707- //e.printStackTrace(System.err);
708- //}
709683}
0 commit comments