Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java Code Style Check with Maven

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Code Style Check
run: mvn -B checkstyle:check --file pom.xml
14 changes: 14 additions & 0 deletions checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
"https://checkstyle.org/dtds/suppressions_1_0.dtd">

<suppressions>
<suppress checks="Javadoc" files="."/>
<suppress checks="MagicNumberCheck" files="."/>
<suppress checks="PackageName" files="."/>
<suppress checks="AbbreviationAsWordInName" files="."/>
<suppress checks="LineLength" files="."/>
<suppress checks="VariableDeclarationUsageDistance" files="."/>
</suppressions>
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<!-- Maven plugin versions -->
<bnd.maven.plugin.version>4.3.1</bnd.maven.plugin.version>
<maven.checkstyle.plugin.version>3.1.1</maven.checkstyle.plugin.version>
<maven.compiler.plugin.version>3.7.0</maven.compiler.plugin.version>
<maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>
<maven.jar.plugin.version>3.0.2</maven.jar.plugin.version>
Expand Down Expand Up @@ -174,6 +175,27 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.plugin.version}</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<violationSeverity>warning</violationSeverity>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<consoleOutput>true</consoleOutput>
<failsOnError>false</failsOnError>
</configuration>
<executions>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/org/java_websocket/SSLSocketChannel2.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package org.java_websocket;

import java.io.EOFException;
Expand Down Expand Up @@ -275,10 +276,10 @@ public int write(ByteBuffer src) throws IOException {
processHandshake();
return 0;
}
// assert ( bufferallocations > 1 ); //see #190
//if( bufferallocations <= 1 ) {
// createBuffers( sslEngine.getSession() );
//}
// assert(bufferallocations > 1); // see #190
// if(bufferallocations <= 1) {
// createBuffers(sslEngine.getSession());
// }
int num = socketChannel.write(wrap(src));
if (writeEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) {
throw new EOFException("Connection is closed");
Expand Down Expand Up @@ -311,10 +312,11 @@ public int read(ByteBuffer dst) throws IOException {
}
}
}
// assert ( bufferallocations > 1 ); //see #190
//if( bufferallocations <= 1 ) {
// createBuffers( sslEngine.getSession() );
//}
// assert(bufferallocations > 1); // see #190
// if (bufferallocations <= 1) {
// createBuffers(sslEngine.getSession());
// }

/* 1. When "dst" is smaller than "inData" readRemaining will fill "dst" with data decoded in a previous read call.
* 2. When "inCrypt" contains more data than "inData" has remaining space, unwrap has to be called on more time(readRemaining)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static boolean batch(WebSocketImpl ws, ByteChannel sockchannel) throws IO
}

if (ws.outQueue.isEmpty() && ws.isFlushAndClose() && ws.getDraft() != null
&& ws.getDraft().getRole() != null && ws.getDraft().getRole() == Role.SERVER) {//
&& ws.getDraft().getRole() != null && ws.getDraft().getRole() == Role.SERVER) {
ws.closeConnection();
}
return c == null || !((WrappedByteChannel) sockchannel).isNeedWrite();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public void run() {
ostream = socket.getOutputStream();

sendHandshake();
} catch ( /*IOException | SecurityException | UnresolvedAddressException | InvalidHandshakeException | ClosedByInterruptException | SocketTimeoutException */Exception e) {
} catch (/*IOException | SecurityException | UnresolvedAddressException | InvalidHandshakeException | ClosedByInterruptException | SocketTimeoutException */Exception e) {
onWebsocketError(engine, e);
engine.closeConnection(CloseFrame.NEVER_CONNECTED, e.getMessage());
return;
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/org/java_websocket/drafts/Draft_6455.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,12 @@ private Framedata translateSingleFrame(ByteBuffer buffer)
int maxpacketsize = buffer.remaining();
int realpacketsize = 2;
translateSingleFrameCheckPacketSize(maxpacketsize, realpacketsize);
byte b1 = buffer.get( /*0*/);
byte b1 = buffer.get(/*0*/);
boolean fin = b1 >> 8 != 0;
boolean rsv1 = (b1 & 0x40) != 0;
boolean rsv2 = (b1 & 0x20) != 0;
boolean rsv3 = (b1 & 0x10) != 0;
byte b2 = buffer.get( /*1*/);
byte b2 = buffer.get(/*1*/);
boolean mask = (b2 & -128) != 0;
int payloadlength = (byte) (b2 & ~(byte) 128);
Opcode optcode = toOpcode((byte) (b1 & 15));
Expand All @@ -548,7 +548,7 @@ private Framedata translateSingleFrame(ByteBuffer buffer)
byte[] maskskey = new byte[4];
buffer.get(maskskey);
for (int i = 0; i < payloadlength; i++) {
payload.put((byte) (buffer.get( /*payloadstart + i*/) ^ maskskey[i % 4]));
payload.put((byte) (buffer.get(/*payloadstart + i*/) ^ maskskey[i % 4]));
}
} else {
payload.put(buffer.array(), buffer.position(), payload.limit());
Expand Down Expand Up @@ -599,15 +599,15 @@ private TranslatedPayloadMetaData translateSingleFramePayloadLength(ByteBuffer b
realpacketsize += 2; // additional length bytes
translateSingleFrameCheckPacketSize(maxpacketsize, realpacketsize);
byte[] sizebytes = new byte[3];
sizebytes[1] = buffer.get( /*1 + 1*/);
sizebytes[2] = buffer.get( /*1 + 2*/);
sizebytes[1] = buffer.get(/*1 + 1*/);
sizebytes[2] = buffer.get(/*1 + 2*/);
payloadlength = new BigInteger(sizebytes).intValue();
} else {
realpacketsize += 8; // additional length bytes
translateSingleFrameCheckPacketSize(maxpacketsize, realpacketsize);
byte[] bytes = new byte[8];
for (int i = 0; i < 8; i++) {
bytes[i] = buffer.get( /*1 + i*/);
bytes[i] = buffer.get(/*1 + i*/);
}
long length = new BigInteger(bytes).longValue();
translateSingleFrameCheckLengthLimit(length);
Expand Down Expand Up @@ -735,7 +735,8 @@ public List<Framedata> translateFrame(ByteBuffer buffer) throws InvalidDataExcep
}
}

while (buffer.hasRemaining()) {// Read as much as possible full frames
// Read as much as possible full frames
while (buffer.hasRemaining()) {
buffer.mark();
try {
cur = translateSingleFrame(buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ public void decodeFrame(Framedata inputFrame) throws InvalidDataException {
try {
decompress(inputFrame.getPayloadData().array(), output);

/*
If a message is "first fragmented and then compressed", as this project does, then the inflater
can not inflate fragments except the first one.
This behavior occurs most likely because those fragments end with "final deflate blocks".
We can check the getRemaining() method to see whether the data we supplied has been decompressed or not.
And if not, we just reset the inflater and decompress again.
Note that this behavior doesn't occur if the message is "first compressed and then fragmented".
*/
/*
If a message is "first fragmented and then compressed", as this project does, then the inflater
can not inflate fragments except the first one.
This behavior occurs most likely because those fragments end with "final deflate blocks".
We can check the getRemaining() method to see whether the data we supplied has been decompressed or not.
And if not, we just reset the inflater and decompress again.
Note that this behavior doesn't occur if the message is "first compressed and then fragmented".
*/
if (inflater.getRemaining() > 0) {
inflater = new Inflater(true);
decompress(inputFrame.getPayloadData().array(), output);
Expand Down Expand Up @@ -196,15 +196,15 @@ public void encodeFrame(Framedata inputFrame) {
output.write(buffer, 0, bytesCompressed);
}

byte outputBytes[] = output.toByteArray();
byte[] outputBytes = output.toByteArray();
int outputLength = outputBytes.length;

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