mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-10 01:10:30 +00:00
parent
925092add3
commit
4980b7355d
@ -29,7 +29,7 @@ import static dan200.computercraft.core.apis.http.websocket.WebsocketClient.MESS
|
|||||||
* @see dan200.computercraft.core.apis.HTTPAPI#websocket On how to open a websocket.
|
* @see dan200.computercraft.core.apis.HTTPAPI#websocket On how to open a websocket.
|
||||||
*/
|
*/
|
||||||
public class WebsocketHandle {
|
public class WebsocketHandle {
|
||||||
private static final CharsetDecoder DECODER = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPLACE);
|
private static final ThreadLocal<CharsetDecoder> DECODER = ThreadLocal.withInitial(() -> StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPLACE));
|
||||||
|
|
||||||
private final IAPIEnvironment environment;
|
private final IAPIEnvironment environment;
|
||||||
private final String address;
|
private final String address;
|
||||||
@ -87,7 +87,7 @@ public class WebsocketHandle {
|
|||||||
websocket.sendBinary(text);
|
websocket.sendBinary(text);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
websocket.sendText(DECODER.decode(text).toString());
|
websocket.sendText(DECODER.get().decode(text).toString());
|
||||||
} catch (CharacterCodingException e) {
|
} catch (CharacterCodingException e) {
|
||||||
// This shouldn't happen, but worth mentioning.
|
// This shouldn't happen, but worth mentioning.
|
||||||
throw new LuaException("Message is not valid UTF8");
|
throw new LuaException("Message is not valid UTF8");
|
||||||
|
Loading…
Reference in New Issue
Block a user