diff --git a/.github/workflows/checkstyle.yml b/.github/workflows/checkstyle.yml
new file mode 100644
index 000000000..8b74e7db5
--- /dev/null
+++ b/.github/workflows/checkstyle.yml
@@ -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
diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml
new file mode 100644
index 000000000..abfbc7857
--- /dev/null
+++ b/checkstyle-suppressions.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 70999a245..99f5c2701 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,6 +19,7 @@
4.3.1
+ 3.1.1
3.7.0
1.6
3.0.2
@@ -174,6 +175,27 @@
org.apache.maven.plugins
maven-compiler-plugin
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ ${maven.checkstyle.plugin.version}
+
+ google_checks.xml
+ warning
+ checkstyle-suppressions.xml
+ checkstyle.suppressions.file
+ true
+ false
+
+
+
+ check
+
+ check
+
+
+
+
diff --git a/src/main/java/org/java_websocket/SSLSocketChannel2.java b/src/main/java/org/java_websocket/SSLSocketChannel2.java
index 983d64c34..d9b9a4c31 100644
--- a/src/main/java/org/java_websocket/SSLSocketChannel2.java
+++ b/src/main/java/org/java_websocket/SSLSocketChannel2.java
@@ -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;
@@ -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");
@@ -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)
*/
diff --git a/src/main/java/org/java_websocket/SocketChannelIOHelper.java b/src/main/java/org/java_websocket/SocketChannelIOHelper.java
index 987ce4093..2d919344a 100644
--- a/src/main/java/org/java_websocket/SocketChannelIOHelper.java
+++ b/src/main/java/org/java_websocket/SocketChannelIOHelper.java
@@ -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();
diff --git a/src/main/java/org/java_websocket/client/WebSocketClient.java b/src/main/java/org/java_websocket/client/WebSocketClient.java
index 8ab3684b8..992eb9670 100644
--- a/src/main/java/org/java_websocket/client/WebSocketClient.java
+++ b/src/main/java/org/java_websocket/client/WebSocketClient.java
@@ -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;
diff --git a/src/main/java/org/java_websocket/drafts/Draft_6455.java b/src/main/java/org/java_websocket/drafts/Draft_6455.java
index e81ebe4fa..35660f713 100644
--- a/src/main/java/org/java_websocket/drafts/Draft_6455.java
+++ b/src/main/java/org/java_websocket/drafts/Draft_6455.java
@@ -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));
@@ -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());
@@ -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);
@@ -735,7 +735,8 @@ public List 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);
diff --git a/src/main/java/org/java_websocket/extensions/permessage_deflate/PerMessageDeflateExtension.java b/src/main/java/org/java_websocket/extensions/permessage_deflate/PerMessageDeflateExtension.java
index 41f4bbb72..c0346b88b 100644
--- a/src/main/java/org/java_websocket/extensions/permessage_deflate/PerMessageDeflateExtension.java
+++ b/src/main/java/org/java_websocket/extensions/permessage_deflate/PerMessageDeflateExtension.java
@@ -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);
@@ -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;
diff --git a/src/main/java/org/java_websocket/util/Base64.java b/src/main/java/org/java_websocket/util/Base64.java
index 175016327..1a39e9c9e 100644
--- a/src/main/java/org/java_websocket/util/Base64.java
+++ b/src/main/java/org/java_websocket/util/Base64.java
@@ -177,22 +177,22 @@ public class Base64 {
/**
* No options specified. Value is zero.
*/
- public final static int NO_OPTIONS = 0;
+ public static final int NO_OPTIONS = 0;
/**
* Specify encoding in first bit. Value is one.
*/
- public final static int ENCODE = 1;
+ public static final int ENCODE = 1;
/**
* Specify that data should be gzip-compressed in second bit. Value is two.
*/
- public final static int GZIP = 2;
+ public static final int GZIP = 2;
/**
* Do break lines when encoding. Value is 8.
*/
- public final static int DO_BREAK_LINES = 8;
+ public static final int DO_BREAK_LINES = 8;
/**
* Encode using Base64-like encoding that is URL- and Filename-safe as described in Section 4 of
@@ -202,14 +202,14 @@ public class Base64 {
* at the very least should not be called Base64 without also specifying that is was encoded using
* the URL- and Filename-safe dialect.
*/
- public final static int URL_SAFE = 16;
+ public static final int URL_SAFE = 16;
/**
* Encode using the special "ordered" dialect of Base64 described here:
* http://www.faqs.org/qa/rfcc-1940.html.
*/
- public final static int ORDERED = 32;
+ public static final int ORDERED = 32;
/* ******** P R I V A T E F I E L D S ******** */
@@ -218,28 +218,28 @@ public class Base64 {
/**
* Maximum line length (76) of Base64 output.
*/
- private final static int MAX_LINE_LENGTH = 76;
+ private static final int MAX_LINE_LENGTH = 76;
/**
* The equals sign (=) as a byte.
*/
- private final static byte EQUALS_SIGN = (byte) '=';
+ private static final byte EQUALS_SIGN = (byte) '=';
/**
* The new line character (\n) as a byte.
*/
- private final static byte NEW_LINE = (byte) '\n';
+ private static final byte NEW_LINE = (byte) '\n';
/**
* Preferred encoding.
*/
- private final static String PREFERRED_ENCODING = "US-ASCII";
+ private static final String PREFERRED_ENCODING = "US-ASCII";
- private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding
+ private static final byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding
/* ******** S T A N D A R D B A S E 6 4 A L P H A B E T ******** */
@@ -248,7 +248,7 @@ public class Base64 {
* The 64 valid Base64 values.
*/
/* Host platform me be something funny like EBCDIC, so we hardcode these values. */
- private final static byte[] _STANDARD_ALPHABET = {
+ private static final byte[] _STANDARD_ALPHABET = {
(byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G',
(byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N',
(byte) 'O', (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U',
@@ -266,29 +266,29 @@ public class Base64 {
* Translates a Base64 value to either its 6-bit reconstruction value or a negative number
* indicating some other meaning.
**/
- private final static byte[] _STANDARD_DECODABET = {
- -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
- -5, -5, // Whitespace: Tab and Linefeed
- -9, -9, // Decimal 11 - 12
- -5, // Whitespace: Carriage Return
+ private static final byte[] _STANDARD_DECODABET = {
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
+ -5, -5, // Whitespace: Tab and Linefeed
+ -9, -9, // Decimal 11 - 12
+ -5, // Whitespace: Carriage Return
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - 26
- -9, -9, -9, -9, -9, // Decimal 27 - 31
- -5, // Whitespace: Space
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42
- 62, // Plus sign at decimal 43
- -9, -9, -9, // Decimal 44 - 46
- 63, // Slash at decimal 47
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine
- -9, -9, -9, // Decimal 58 - 60
- -1, // Equals sign at decimal 61
- -9, -9, -9, // Decimal 62 - 64
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' through 'N'
- 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' through 'Z'
- -9, -9, -9, -9, -9, -9, // Decimal 91 - 96
+ -9, -9, -9, -9, -9, // Decimal 27 - 31
+ -5, // Whitespace: Space
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42
+ 62, // Plus sign at decimal 43
+ -9, -9, -9, // Decimal 44 - 46
+ 63, // Slash at decimal 47
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine
+ -9, -9, -9, // Decimal 58 - 60
+ -1, // Equals sign at decimal 61
+ -9, -9, -9, // Decimal 62 - 64
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' through 'N'
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' through 'Z'
+ -9, -9, -9, -9, -9, -9, // Decimal 91 - 96
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, // Letters 'a' through 'm'
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // Letters 'n' through 'z'
- -9, -9, -9, -9, -9 // Decimal 123 - 127
- , -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 128 - 139
+ -9, -9, -9, -9, -9, // Decimal 123 - 127
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 128 - 139
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 140 - 152
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 153 - 165
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 166 - 178
@@ -297,7 +297,7 @@ public class Base64 {
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 205 - 217
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 218 - 230
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 231 - 243
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9 // Decimal 244 - 255
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9 // Decimal 244 - 255
};
@@ -308,7 +308,7 @@ public class Base64 {
* http://www.faqs.org/rfcs/rfc3548.html.
* Notice that the last two bytes become "hyphen" and "underscore" instead of "plus" and "slash."
*/
- private final static byte[] _URL_SAFE_ALPHABET = {
+ private static final byte[] _URL_SAFE_ALPHABET = {
(byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G',
(byte) 'H', (byte) 'I', (byte) 'J', (byte) 'K', (byte) 'L', (byte) 'M', (byte) 'N',
(byte) 'O', (byte) 'P', (byte) 'Q', (byte) 'R', (byte) 'S', (byte) 'T', (byte) 'U',
@@ -324,33 +324,33 @@ public class Base64 {
/**
* Used in decoding URL- and Filename-safe dialects of Base64.
*/
- private final static byte[] _URL_SAFE_DECODABET = {
- -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
- -5, -5, // Whitespace: Tab and Linefeed
- -9, -9, // Decimal 11 - 12
- -5, // Whitespace: Carriage Return
+ private static final byte[] _URL_SAFE_DECODABET = {
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
+ -5, -5, // Whitespace: Tab and Linefeed
+ -9, -9, // Decimal 11 - 12
+ -5, // Whitespace: Carriage Return
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - 26
- -9, -9, -9, -9, -9, // Decimal 27 - 31
- -5, // Whitespace: Space
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42
- -9, // Plus sign at decimal 43
- -9, // Decimal 44
- 62, // Minus sign at decimal 45
- -9, // Decimal 46
- -9, // Slash at decimal 47
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine
- -9, -9, -9, // Decimal 58 - 60
- -1, // Equals sign at decimal 61
- -9, -9, -9, // Decimal 62 - 64
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' through 'N'
- 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' through 'Z'
- -9, -9, -9, -9, // Decimal 91 - 94
- 63, // Underscore at decimal 95
- -9, // Decimal 96
+ -9, -9, -9, -9, -9, // Decimal 27 - 31
+ -5, // Whitespace: Space
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42
+ -9, // Plus sign at decimal 43
+ -9, // Decimal 44
+ 62, // Minus sign at decimal 45
+ -9, // Decimal 46
+ -9, // Slash at decimal 47
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, // Numbers zero through nine
+ -9, -9, -9, // Decimal 58 - 60
+ -1, // Equals sign at decimal 61
+ -9, -9, -9, // Decimal 62 - 64
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, // Letters 'A' through 'N'
+ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // Letters 'O' through 'Z'
+ -9, -9, -9, -9, // Decimal 91 - 94
+ 63, // Underscore at decimal 95
+ -9, // Decimal 96
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, // Letters 'a' through 'm'
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // Letters 'n' through 'z'
- -9, -9, -9, -9, -9 // Decimal 123 - 127
- , -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 128 - 139
+ -9, -9, -9, -9, -9, // Decimal 123 - 127
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 128 - 139
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 140 - 152
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 153 - 165
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 166 - 178
@@ -359,7 +359,7 @@ public class Base64 {
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 205 - 217
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 218 - 230
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 231 - 243
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9 // Decimal 244 - 255
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9 // Decimal 244 - 255
};
@@ -370,7 +370,7 @@ public class Base64 {
* I don't get the point of this technique, but someone requested it, and it is described here:
* http://www.faqs.org/qa/rfcc-1940.html.
*/
- private final static byte[] _ORDERED_ALPHABET = {
+ private static final byte[] _ORDERED_ALPHABET = {
(byte) '-',
(byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4',
(byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9',
@@ -388,33 +388,33 @@ public class Base64 {
/**
* Used in decoding the "ordered" dialect of Base64.
*/
- private final static byte[] _ORDERED_DECODABET = {
- -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
- -5, -5, // Whitespace: Tab and Linefeed
- -9, -9, // Decimal 11 - 12
- -5, // Whitespace: Carriage Return
+ private static final byte[] _ORDERED_DECODABET = {
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 0 - 8
+ -5, -5, // Whitespace: Tab and Linefeed
+ -9, -9, // Decimal 11 - 12
+ -5, // Whitespace: Carriage Return
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 14 - 26
- -9, -9, -9, -9, -9, // Decimal 27 - 31
- -5, // Whitespace: Space
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42
- -9, // Plus sign at decimal 43
- -9, // Decimal 44
- 0, // Minus sign at decimal 45
- -9, // Decimal 46
- -9, // Slash at decimal 47
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // Numbers zero through nine
- -9, -9, -9, // Decimal 58 - 60
- -1, // Equals sign at decimal 61
- -9, -9, -9, // Decimal 62 - 64
+ -9, -9, -9, -9, -9, // Decimal 27 - 31
+ -5, // Whitespace: Space
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 33 - 42
+ -9, // Plus sign at decimal 43
+ -9, // Decimal 44
+ 0, // Minus sign at decimal 45
+ -9, // Decimal 46
+ -9, // Slash at decimal 47
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, // Numbers zero through nine
+ -9, -9, -9, // Decimal 58 - 60
+ -1, // Equals sign at decimal 61
+ -9, -9, -9, // Decimal 62 - 64
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, // Letters 'A' through 'M'
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, // Letters 'N' through 'Z'
- -9, -9, -9, -9, // Decimal 91 - 94
- 37, // Underscore at decimal 95
- -9, // Decimal 96
+ -9, -9, -9, -9, // Decimal 91 - 94
+ 37, // Underscore at decimal 95
+ -9, // Decimal 96
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, // Letters 'a' through 'm'
51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, // Letters 'n' through 'z'
- -9, -9, -9, -9, -9 // Decimal 123 - 127
- , -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 128 - 139
+ -9, -9, -9, -9, -9, // Decimal 123 - 127
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 128 - 139
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 140 - 152
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 153 - 165
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 166 - 178
@@ -423,7 +423,7 @@ public class Base64 {
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 205 - 217
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 218 - 230
-9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, // Decimal 231 - 243
- -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9 // Decimal 244 - 255
+ -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9, -9 // Decimal 244 - 255
};
@@ -435,7 +435,7 @@ public class Base64 {
* possible, though silly, to specify ORDERED and URLSAFE in which case one of them will be
* picked, though there is no guarantee as to which one will be picked.
*/
- private final static byte[] getAlphabet(int options) {
+ private static final byte[] getAlphabet(int options) {
if ((options & URL_SAFE) == URL_SAFE) {
return _URL_SAFE_ALPHABET;
} else if ((options & ORDERED) == ORDERED) {
@@ -451,7 +451,7 @@ private final static byte[] getAlphabet(int options) {
* possible, though silly, to specify ORDERED and URL_SAFE in which case one of them will be
* picked, though there is no guarantee as to which one will be picked.
*/
- private final static byte[] getDecodabet(int options) {
+ private static final byte[] getDecodabet(int options) {
if ((options & URL_SAFE) == URL_SAFE) {
return _URL_SAFE_DECODABET;
} else if ((options & ORDERED) == ORDERED) {
@@ -622,8 +622,7 @@ public static String encodeBytes(byte[] source, int off, int len, int options)
// Return value according to relevant encoding.
try {
return new String(encoded, PREFERRED_ENCODING);
- } // end try
- catch (java.io.UnsupportedEncodingException uue) {
+ } catch (java.io.UnsupportedEncodingException uue) {
return new String(encoded);
} // end catch
@@ -682,13 +681,11 @@ public static byte[] encodeBytesToBytes(byte[] source, int off, int len, int opt
gzos.write(source, off, len);
gzos.close();
- } // end try
- catch (java.io.IOException e) {
+ } catch (java.io.IOException e) {
// Catch it and then throw it immediately so that
// the finally{} block is called for cleanup.
throw e;
- } // end catch
- finally {
+ } finally {
try {
if (gzos != null) {
gzos.close();
@@ -720,6 +717,7 @@ public static byte[] encodeBytesToBytes(byte[] source, int off, int len, int opt
//byte[] outBuff = new byte[ ( len43 ) // Main 4:3
// + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding
// + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines
+
// Try to determine more precisely how big the array needs to be.
// If we get it right, we don't have to do an array copy, and
// we save a bunch of memory.
@@ -742,7 +740,7 @@ public static byte[] encodeBytesToBytes(byte[] source, int off, int len, int opt
e++;
lineLength = 0;
} // end if: end of line
- } // en dfor: each piece of array
+ } // end for: each piece of array
if (d < len) {
encode3to4(source, d + off, len - d, outBuff, e, options);
diff --git a/src/main/java/org/java_websocket/util/Charsetfunctions.java b/src/main/java/org/java_websocket/util/Charsetfunctions.java
index 78fd8b552..0cea88ec4 100644
--- a/src/main/java/org/java_websocket/util/Charsetfunctions.java
+++ b/src/main/java/org/java_websocket/util/Charsetfunctions.java
@@ -25,14 +25,12 @@
package org.java_websocket.util;
-import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
+import java.nio.charset.StandardCharsets;
import org.java_websocket.exceptions.InvalidDataException;
-import org.java_websocket.exceptions.InvalidEncodingException;
import org.java_websocket.framing.CloseFrame;
public class Charsetfunctions {
@@ -49,22 +47,14 @@ private Charsetfunctions() {
* @return UTF-8 encoding in bytes
*/
public static byte[] utf8Bytes(String s) {
- try {
- return s.getBytes("UTF8");
- } catch (UnsupportedEncodingException e) {
- throw new InvalidEncodingException(e);
- }
+ return s.getBytes(StandardCharsets.UTF_8);
}
/*
* @return ASCII encoding in bytes
*/
public static byte[] asciiBytes(String s) {
- try {
- return s.getBytes("ASCII");
- } catch (UnsupportedEncodingException e) {
- throw new InvalidEncodingException(e);
- }
+ return s.getBytes(StandardCharsets.US_ASCII);
}
public static String stringAscii(byte[] bytes) {
@@ -72,11 +62,7 @@ public static String stringAscii(byte[] bytes) {
}
public static String stringAscii(byte[] bytes, int offset, int length) {
- try {
- return new String(bytes, offset, length, "ASCII");
- } catch (UnsupportedEncodingException e) {
- throw new InvalidEncodingException(e);
- }
+ return new String(bytes, offset, length, StandardCharsets.US_ASCII);
}
public static String stringUtf8(byte[] bytes) throws InvalidDataException {
@@ -84,7 +70,7 @@ public static String stringUtf8(byte[] bytes) throws InvalidDataException {
}
public static String stringUtf8(ByteBuffer bytes) throws InvalidDataException {
- CharsetDecoder decode = Charset.forName("UTF8").newDecoder();
+ CharsetDecoder decode = StandardCharsets.UTF_8.newDecoder();
decode.onMalformedInput(codingErrorAction);
decode.onUnmappableCharacter(codingErrorAction);
String s;
diff --git a/src/test/java/org/java_websocket/issues/Issue997Test.java b/src/test/java/org/java_websocket/issues/Issue997Test.java
index 3c3b80641..be227cef7 100644
--- a/src/test/java/org/java_websocket/issues/Issue997Test.java
+++ b/src/test/java/org/java_websocket/issues/Issue997Test.java
@@ -175,8 +175,6 @@ protected void onSetSSLParameters(SSLParameters sslParameters) {
}
- ;
-
private static class SSLWebSocketServer extends WebSocketServer {