Skip to content

Commit 60a0fc9

Browse files
committed
Change the UTF8_CHARSET property into a String, for better JVM compatibility.
1 parent 6246fbd commit 60a0fc9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/net/tootallnate/websocket/WebSocket.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.tootallnate.websocket;
22

33
import java.io.IOException;
4+
import java.io.UnsupportedEncodingException;
45
import java.nio.ByteBuffer;
56
import java.nio.channels.NotYetConnectedException;
67
import java.nio.channels.SocketChannel;
@@ -31,7 +32,7 @@ public final class WebSocket {
3132
/**
3233
* The WebSocket protocol expects UTF-8 encoded bytes.
3334
*/
34-
public static final Charset UTF8_CHARSET = Charset.forName("UTF-8");
35+
public static final String UTF8_CHARSET = "UTF-8";
3536
/**
3637
* The byte representing CR, or Carriage Return, or \r
3738
*/
@@ -224,7 +225,13 @@ private void recieveFrame() {
224225
// currentFrame will be null if END_OF_FRAME was send directly after
225226
// START_OF_FRAME, thus we will send 'null' as the sent message.
226227
if (this.currentFrame != null) {
227-
textFrame = new String(this.currentFrame.array(), UTF8_CHARSET);
228+
try {
229+
textFrame = new String(this.currentFrame.array(), UTF8_CHARSET);
230+
} catch (UnsupportedEncodingException ex) {
231+
// TODO: Fire an 'onError' handler here
232+
ex.printStackTrace();
233+
textFrame = "";
234+
}
228235
}
229236
this.wsl.onMessage(this, textFrame);
230237

0 commit comments

Comments
 (0)