Skip to content

Commit 479462a

Browse files
authored
Merge pull request TooTallNate#17 from dota17/cleanup-code
update suppressions and cleanup code
2 parents d2564df + b0baf6c commit 479462a

File tree

6 files changed

+46
-42
lines changed

6 files changed

+46
-42
lines changed

checkstyle-suppressions.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
<suppress checks="AbbreviationAsWordInName" files="."/>
1212
<suppress checks="LineLength" files="."/>
1313
<suppress checks="VariableDeclarationUsageDistance" files="."/>
14-
</suppressions>
14+
<suppress checks="OverloadMethodsDeclarationOrder" files="."/>
15+
<suppress checks="NonEmptyAtclauseDescription" files="."/>
16+
<suppress checks="TypeName" files="Draft_6455.java"/>
17+
<suppress checks="RightCurly" files="Base64.java"/>
18+
</suppressions>

src/main/java/org/java_websocket/SocketChannelIOHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public static boolean batch(WebSocketImpl ws, ByteChannel sockchannel) throws IO
9494
}
9595
}
9696
} else {
97-
do {// FIXME writing as much as possible is unfair!!
97+
do {
98+
// FIXME writing as much as possible is unfair!!
9899
/*int written = */
99100
sockchannel.write(buffer);
100101
if (buffer.remaining() > 0) {

src/main/java/org/java_websocket/WebSocketImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ public WebSocketImpl(WebSocketListener listener, List<Draft> drafts) {
204204
* @param draft The draft which should be used
205205
*/
206206
public WebSocketImpl(WebSocketListener listener, Draft draft) {
207-
if (listener == null || (draft == null && role
208-
== Role.SERVER))// socket can be null because we want do be able to create the object without already having a bound channel
209-
{
207+
// socket can be null because we want do be able to create the object without already having a bound channel
208+
if (listener == null || (draft == null && role == Role.SERVER)) {
210209
throw new IllegalArgumentException("parameters must not be null");
211210
}
212211
this.outQueue = new LinkedBlockingQueue<ByteBuffer>();

src/main/java/org/java_websocket/drafts/Draft_6455.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,12 @@ public HandshakeBuilder postProcessHandshakeResponseAsServer(ClientHandshake req
443443
@Override
444444
public Draft copyInstance() {
445445
ArrayList<IExtension> newExtensions = new ArrayList<IExtension>();
446-
for (IExtension iExtension : getKnownExtensions()) {
447-
newExtensions.add(iExtension.copyInstance());
446+
for (IExtension extension : getKnownExtensions()) {
447+
newExtensions.add(extension.copyInstance());
448448
}
449449
ArrayList<IProtocol> newProtocols = new ArrayList<IProtocol>();
450-
for (IProtocol iProtocol : getKnownProtocols()) {
451-
newProtocols.add(iProtocol.copyInstance());
450+
for (IProtocol protocol : getKnownProtocols()) {
451+
newProtocols.add(protocol.copyInstance());
452452
}
453453
return new Draft_6455(newExtensions, newProtocols, maxFrameSize);
454454
}
@@ -589,8 +589,8 @@ private Framedata translateSingleFrame(ByteBuffer buffer)
589589
private TranslatedPayloadMetaData translateSingleFramePayloadLength(ByteBuffer buffer,
590590
Opcode optcode, int oldPayloadlength, int maxpacketsize, int oldRealpacketsize)
591591
throws InvalidFrameException, IncompleteException, LimitExceededException {
592-
int payloadlength = oldPayloadlength,
593-
realpacketsize = oldRealpacketsize;
592+
int payloadlength = oldPayloadlength;
593+
int realpacketsize = oldRealpacketsize;
594594
if (optcode == Opcode.PING || optcode == Opcode.PONG || optcode == Opcode.CLOSING) {
595595
log.trace("Invalid frame: more than 125 octets");
596596
throw new InvalidFrameException("more than 125 octets");
@@ -660,19 +660,16 @@ private void translateSingleFrameCheckPacketSize(int maxpacketsize, int realpack
660660
* @return byte that represents which RSV bit is set.
661661
*/
662662
private byte getRSVByte(int rsv) {
663-
if (rsv == 1) // 0100 0000
664-
{
665-
return 0x40;
666-
}
667-
if (rsv == 2) // 0010 0000
668-
{
669-
return 0x20;
670-
}
671-
if (rsv == 3) // 0001 0000
672-
{
673-
return 0x10;
663+
switch (rsv) {
664+
case 1 : // 0100 0000
665+
return 0x40;
666+
case 2 : // 0010 0000
667+
return 0x20;
668+
case 3 : // 0001 0000
669+
return 0x10;
670+
default:
671+
return 0;
674672
}
675-
return 0;
676673
}
677674

678675
/**

src/main/java/org/java_websocket/server/WebSocketServer.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,17 @@ public void run() {
361361
return;
362362
}
363363
try {
364-
int iShutdownCount = 5;
364+
int shutdownCount = 5;
365365
int selectTimeout = 0;
366-
while (!selectorthread.isInterrupted() && iShutdownCount != 0) {
366+
while (!selectorthread.isInterrupted() && shutdownCount != 0) {
367367
SelectionKey key = null;
368368
try {
369369
if (isclosed.get()) {
370370
selectTimeout = 5;
371371
}
372372
int keyCount = selector.select(selectTimeout);
373373
if (keyCount == 0 && isclosed.get()) {
374-
iShutdownCount--;
374+
shutdownCount--;
375375
}
376376
Set<SelectionKey> keys = selector.selectedKeys();
377377
Iterator<SelectionKey> i = keys.iterator();
@@ -993,15 +993,15 @@ public void broadcast(String text, Collection<WebSocket> clients) {
993993
* @param clients the clients to send the message to
994994
*/
995995
private void doBroadcast(Object data, Collection<WebSocket> clients) {
996-
String sData = null;
996+
String strData = null;
997997
if (data instanceof String) {
998-
sData = (String) data;
998+
strData = (String) data;
999999
}
1000-
ByteBuffer bData = null;
1000+
ByteBuffer byteData = null;
10011001
if (data instanceof ByteBuffer) {
1002-
bData = (ByteBuffer) data;
1002+
byteData = (ByteBuffer) data;
10031003
}
1004-
if (sData == null && bData == null) {
1004+
if (strData == null && byteData == null) {
10051005
return;
10061006
}
10071007
Map<Draft, List<Framedata>> draftFrames = new HashMap<Draft, List<Framedata>>();
@@ -1012,7 +1012,7 @@ private void doBroadcast(Object data, Collection<WebSocket> clients) {
10121012
for (WebSocket client : clientCopy) {
10131013
if (client != null) {
10141014
Draft draft = client.getDraft();
1015-
fillFrames(draft, draftFrames, sData, bData);
1015+
fillFrames(draft, draftFrames, strData, byteData);
10161016
try {
10171017
client.sendFrame(draftFrames.get(draft));
10181018
} catch (WebsocketNotConnectedException e) {
@@ -1027,18 +1027,18 @@ private void doBroadcast(Object data, Collection<WebSocket> clients) {
10271027
*
10281028
* @param draft The draft to use
10291029
* @param draftFrames The list of frames per draft to fill
1030-
* @param sData the string data, can be null
1031-
* @param bData the byte buffer data, can be null
1030+
* @param strData the string data, can be null
1031+
* @param byteData the byte buffer data, can be null
10321032
*/
1033-
private void fillFrames(Draft draft, Map<Draft, List<Framedata>> draftFrames, String sData,
1034-
ByteBuffer bData) {
1033+
private void fillFrames(Draft draft, Map<Draft, List<Framedata>> draftFrames, String strData,
1034+
ByteBuffer byteData) {
10351035
if (!draftFrames.containsKey(draft)) {
10361036
List<Framedata> frames = null;
1037-
if (sData != null) {
1038-
frames = draft.createFrames(sData, false);
1037+
if (strData != null) {
1038+
frames = draft.createFrames(strData, false);
10391039
}
1040-
if (bData != null) {
1041-
frames = draft.createFrames(bData, false);
1040+
if (byteData != null) {
1041+
frames = draft.createFrames(byteData, false);
10421042
}
10431043
if (frames != null) {
10441044
draftFrames.put(draft, frames);

src/main/java/org/java_websocket/util/Base64.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ private static byte[] encode3to4(
517517
byte[] source, int srcOffset, int numSigBytes,
518518
byte[] destination, int destOffset, int options) {
519519

520-
byte[] ALPHABET = getAlphabet(options);
520+
final byte[] ALPHABET = getAlphabet(options);
521521

522522
// 1 2 3
523523
// 01234567890123456789012345678901 Bit position
@@ -691,18 +691,21 @@ public static byte[] encodeBytesToBytes(byte[] source, int off, int len, int opt
691691
gzos.close();
692692
}
693693
} catch (Exception e) {
694+
// do nothing
694695
}
695696
try {
696697
if (b64os != null) {
697698
b64os.close();
698699
}
699700
} catch (Exception e) {
701+
// do nothing
700702
}
701703
try {
702704
if (baos != null) {
703705
baos.close();
704706
}
705707
} catch (Exception e) {
708+
// do nothing
706709
}
707710
} // end finally
708711

@@ -818,7 +821,7 @@ private static int decode4to3(
818821
destination.length, destOffset));
819822
} // end if
820823

821-
byte[] DECODABET = getDecodabet(options);
824+
final byte[] DECODABET = getDecodabet(options);
822825

823826
// Example: Dk==
824827
if (source[srcOffset + 2] == EQUALS_SIGN) {

0 commit comments

Comments
 (0)