Skip to content

Commit 1832346

Browse files
committed
cleanup code
1 parent b727da4 commit 1832346

7 files changed

Lines changed: 128 additions & 123 deletions

File tree

checkstyle-suppressions.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
<suppressions>
88
<suppress checks="Javadoc" files="."/>
99
<suppress checks="MagicNumberCheck" files="."/>
10+
<suppress checks="PackageName" files="."/>
11+
<suppress checks="AbbreviationAsWordInName" files="."/>
12+
<suppress checks="LineLength" files="."/>
13+
<suppress checks="VariableDeclarationUsageDistance" files="."/>
1014
</suppressions>

src/main/java/org/java_websocket/SSLSocketChannel2.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2323
* OTHER DEALINGS IN THE SOFTWARE.
2424
*/
25+
2526
package org.java_websocket;
2627

2728
import java.io.EOFException;
@@ -275,10 +276,10 @@ public int write(ByteBuffer src) throws IOException {
275276
processHandshake();
276277
return 0;
277278
}
278-
// assert ( bufferallocations > 1 ); //see #190
279-
//if( bufferallocations <= 1 ) {
280-
// createBuffers( sslEngine.getSession() );
281-
//}
279+
// assert(bufferallocations > 1); // see #190
280+
// if(bufferallocations <= 1) {
281+
// createBuffers(sslEngine.getSession());
282+
// }
282283
int num = socketChannel.write(wrap(src));
283284
if (writeEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) {
284285
throw new EOFException("Connection is closed");
@@ -311,10 +312,11 @@ public int read(ByteBuffer dst) throws IOException {
311312
}
312313
}
313314
}
314-
// assert ( bufferallocations > 1 ); //see #190
315-
//if( bufferallocations <= 1 ) {
316-
// createBuffers( sslEngine.getSession() );
317-
//}
315+
// assert(bufferallocations > 1); // see #190
316+
// if (bufferallocations <= 1) {
317+
// createBuffers(sslEngine.getSession());
318+
// }
319+
318320
/* 1. When "dst" is smaller than "inData" readRemaining will fill "dst" with data decoded in a previous read call.
319321
* 2. When "inCrypt" contains more data than "inData" has remaining space, unwrap has to be called on more time(readRemaining)
320322
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static boolean batch(WebSocketImpl ws, ByteChannel sockchannel) throws IO
107107
}
108108

109109
if (ws.outQueue.isEmpty() && ws.isFlushAndClose() && ws.getDraft() != null
110-
&& ws.getDraft().getRole() != null && ws.getDraft().getRole() == Role.SERVER) {//
110+
&& ws.getDraft().getRole() != null && ws.getDraft().getRole() == Role.SERVER) {
111111
ws.closeConnection();
112112
}
113113
return c == null || !((WrappedByteChannel) sockchannel).isNeedWrite();

src/main/java/org/java_websocket/client/WebSocketClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public void run() {
498498
ostream = socket.getOutputStream();
499499

500500
sendHandshake();
501-
} catch ( /*IOException | SecurityException | UnresolvedAddressException | InvalidHandshakeException | ClosedByInterruptException | SocketTimeoutException */Exception e) {
501+
} catch (/*IOException | SecurityException | UnresolvedAddressException | InvalidHandshakeException | ClosedByInterruptException | SocketTimeoutException */Exception e) {
502502
onWebsocketError(engine, e);
503503
engine.closeConnection(CloseFrame.NEVER_CONNECTED, e.getMessage());
504504
return;

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,12 @@ private Framedata translateSingleFrame(ByteBuffer buffer)
522522
int maxpacketsize = buffer.remaining();
523523
int realpacketsize = 2;
524524
translateSingleFrameCheckPacketSize(maxpacketsize, realpacketsize);
525-
byte b1 = buffer.get( /*0*/);
525+
byte b1 = buffer.get(/*0*/);
526526
boolean fin = b1 >> 8 != 0;
527527
boolean rsv1 = (b1 & 0x40) != 0;
528528
boolean rsv2 = (b1 & 0x20) != 0;
529529
boolean rsv3 = (b1 & 0x10) != 0;
530-
byte b2 = buffer.get( /*1*/);
530+
byte b2 = buffer.get(/*1*/);
531531
boolean mask = (b2 & -128) != 0;
532532
int payloadlength = (byte) (b2 & ~(byte) 128);
533533
Opcode optcode = toOpcode((byte) (b1 & 15));
@@ -548,7 +548,7 @@ private Framedata translateSingleFrame(ByteBuffer buffer)
548548
byte[] maskskey = new byte[4];
549549
buffer.get(maskskey);
550550
for (int i = 0; i < payloadlength; i++) {
551-
payload.put((byte) (buffer.get( /*payloadstart + i*/) ^ maskskey[i % 4]));
551+
payload.put((byte) (buffer.get(/*payloadstart + i*/) ^ maskskey[i % 4]));
552552
}
553553
} else {
554554
payload.put(buffer.array(), buffer.position(), payload.limit());
@@ -599,15 +599,15 @@ private TranslatedPayloadMetaData translateSingleFramePayloadLength(ByteBuffer b
599599
realpacketsize += 2; // additional length bytes
600600
translateSingleFrameCheckPacketSize(maxpacketsize, realpacketsize);
601601
byte[] sizebytes = new byte[3];
602-
sizebytes[1] = buffer.get( /*1 + 1*/);
603-
sizebytes[2] = buffer.get( /*1 + 2*/);
602+
sizebytes[1] = buffer.get(/*1 + 1*/);
603+
sizebytes[2] = buffer.get(/*1 + 2*/);
604604
payloadlength = new BigInteger(sizebytes).intValue();
605605
} else {
606606
realpacketsize += 8; // additional length bytes
607607
translateSingleFrameCheckPacketSize(maxpacketsize, realpacketsize);
608608
byte[] bytes = new byte[8];
609609
for (int i = 0; i < 8; i++) {
610-
bytes[i] = buffer.get( /*1 + i*/);
610+
bytes[i] = buffer.get(/*1 + i*/);
611611
}
612612
long length = new BigInteger(bytes).longValue();
613613
translateSingleFrameCheckLengthLimit(length);
@@ -735,7 +735,8 @@ public List<Framedata> translateFrame(ByteBuffer buffer) throws InvalidDataExcep
735735
}
736736
}
737737

738-
while (buffer.hasRemaining()) {// Read as much as possible full frames
738+
// Read as much as possible full frames
739+
while (buffer.hasRemaining()) {
739740
buffer.mark();
740741
try {
741742
cur = translateSingleFrame(buffer);

src/main/java/org/java_websocket/extensions/permessage_deflate/PerMessageDeflateExtension.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ public void decodeFrame(Framedata inputFrame) throws InvalidDataException {
123123
try {
124124
decompress(inputFrame.getPayloadData().array(), output);
125125

126-
/*
127-
If a message is "first fragmented and then compressed", as this project does, then the inflater
128-
can not inflate fragments except the first one.
129-
This behavior occurs most likely because those fragments end with "final deflate blocks".
130-
We can check the getRemaining() method to see whether the data we supplied has been decompressed or not.
131-
And if not, we just reset the inflater and decompress again.
132-
Note that this behavior doesn't occur if the message is "first compressed and then fragmented".
133-
*/
126+
/*
127+
If a message is "first fragmented and then compressed", as this project does, then the inflater
128+
can not inflate fragments except the first one.
129+
This behavior occurs most likely because those fragments end with "final deflate blocks".
130+
We can check the getRemaining() method to see whether the data we supplied has been decompressed or not.
131+
And if not, we just reset the inflater and decompress again.
132+
Note that this behavior doesn't occur if the message is "first compressed and then fragmented".
133+
*/
134134
if (inflater.getRemaining() > 0) {
135135
inflater = new Inflater(true);
136136
decompress(inputFrame.getPayloadData().array(), output);
@@ -199,12 +199,12 @@ public void encodeFrame(Framedata inputFrame) {
199199
byte[] outputBytes = output.toByteArray();
200200
int outputLength = outputBytes.length;
201201

202-
/*
203-
https://tools.ietf.org/html/rfc7692#section-7.2.1 states that if the final fragment's compressed
204-
payload ends with 0x00 0x00 0xff 0xff, they should be removed.
205-
To simulate removal, we just pass 4 bytes less to the new payload
206-
if the frame is final and outputBytes ends with 0x00 0x00 0xff 0xff.
207-
*/
202+
/*
203+
https://tools.ietf.org/html/rfc7692#section-7.2.1 states that if the final fragment's compressed
204+
payload ends with 0x00 0x00 0xff 0xff, they should be removed.
205+
To simulate removal, we just pass 4 bytes less to the new payload
206+
if the frame is final and outputBytes ends with 0x00 0x00 0xff 0xff.
207+
*/
208208
if (inputFrame.isFin()) {
209209
if (endsWithTail(outputBytes)) {
210210
outputLength -= TAIL_BYTES.length;

0 commit comments

Comments
 (0)