Skip to content

Commit b04a5ad

Browse files
committed
optimize code and remove empty line
1 parent a797dfb commit b04a5ad

File tree

3 files changed

+6
-22
lines changed

3 files changed

+6
-22
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public void encodeFrame(Framedata inputFrame) {
196196
output.write(buffer, 0, bytesCompressed);
197197
}
198198

199-
byte outputBytes[] = output.toByteArray();
199+
byte[] outputBytes = output.toByteArray();
200200
int outputLength = outputBytes.length;
201201

202202
/*

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525

2626
package org.java_websocket.util;
2727

28-
import java.io.UnsupportedEncodingException;
2928
import java.nio.ByteBuffer;
3029
import java.nio.charset.CharacterCodingException;
31-
import java.nio.charset.Charset;
3230
import java.nio.charset.CharsetDecoder;
3331
import java.nio.charset.CodingErrorAction;
32+
import java.nio.charset.StandardCharsets;
3433
import org.java_websocket.exceptions.InvalidDataException;
35-
import org.java_websocket.exceptions.InvalidEncodingException;
3634
import org.java_websocket.framing.CloseFrame;
3735

3836
public class Charsetfunctions {
@@ -49,42 +47,30 @@ private Charsetfunctions() {
4947
* @return UTF-8 encoding in bytes
5048
*/
5149
public static byte[] utf8Bytes(String s) {
52-
try {
53-
return s.getBytes("UTF8");
54-
} catch (UnsupportedEncodingException e) {
55-
throw new InvalidEncodingException(e);
56-
}
50+
return s.getBytes(StandardCharsets.UTF_8);
5751
}
5852

5953
/*
6054
* @return ASCII encoding in bytes
6155
*/
6256
public static byte[] asciiBytes(String s) {
63-
try {
64-
return s.getBytes("ASCII");
65-
} catch (UnsupportedEncodingException e) {
66-
throw new InvalidEncodingException(e);
67-
}
57+
return s.getBytes(StandardCharsets.US_ASCII);
6858
}
6959

7060
public static String stringAscii(byte[] bytes) {
7161
return stringAscii(bytes, 0, bytes.length);
7262
}
7363

7464
public static String stringAscii(byte[] bytes, int offset, int length) {
75-
try {
76-
return new String(bytes, offset, length, "ASCII");
77-
} catch (UnsupportedEncodingException e) {
78-
throw new InvalidEncodingException(e);
79-
}
65+
return new String(bytes, offset, length, StandardCharsets.US_ASCII);
8066
}
8167

8268
public static String stringUtf8(byte[] bytes) throws InvalidDataException {
8369
return stringUtf8(ByteBuffer.wrap(bytes));
8470
}
8571

8672
public static String stringUtf8(ByteBuffer bytes) throws InvalidDataException {
87-
CharsetDecoder decode = Charset.forName("UTF8").newDecoder();
73+
CharsetDecoder decode = StandardCharsets.UTF_8.newDecoder();
8874
decode.onMalformedInput(codingErrorAction);
8975
decode.onUnmappableCharacter(codingErrorAction);
9076
String s;

src/test/java/org/java_websocket/issues/Issue997Test.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ protected void onSetSSLParameters(SSLParameters sslParameters) {
175175

176176
}
177177

178-
;
179-
180178

181179
private static class SSLWebSocketServer extends WebSocketServer {
182180

0 commit comments

Comments
 (0)