1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-09 06:31:08 +01:00

Use StandardCharsets.(UTF_8|US_ASCII)

This also gets rid of a ton of UnsupportedEncodingException s.
This commit is contained in:
Florian Schmaus 2019-05-08 11:34:40 +02:00
parent 2a4d110b22
commit d2f5efcb20
33 changed files with 125 additions and 227 deletions

View file

@ -19,10 +19,10 @@ package org.jivesoftware.smackx.bytestreams.socks5;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@ -37,7 +37,6 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.SmackException.SmackMessageException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.util.CloseableUtil;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream.StreamHost;
@ -202,13 +201,7 @@ public class Socks5Client {
* @return SOCKS5 connection request message
*/
private byte[] createSocks5ConnectRequest() {
byte[] addr;
try {
addr = digest.getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
byte[] addr = digest.getBytes(StandardCharsets.UTF_8);
byte[] data = new byte[7 + addr.length];
data[0] = (byte) 0x05; // version (SOCKS5)

View file

@ -24,6 +24,7 @@ import java.net.NetworkInterface;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
@ -39,7 +40,6 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.util.CloseableUtil;
import org.jivesoftware.smack.util.StringUtils;
/**
* The Socks5Proxy class represents a local SOCKS5 proxy server. It can be enabled/disabled by
@ -468,7 +468,7 @@ public final class Socks5Proxy {
byte[] connectionRequest = Socks5Utils.receiveSocks5Message(in);
// extract digest
String responseDigest = new String(connectionRequest, 5, connectionRequest[4], StringUtils.UTF8);
String responseDigest = new String(connectionRequest, 5, connectionRequest[4], StandardCharsets.UTF_8);
// return error if digest is not allowed
if (!Socks5Proxy.this.allowedConnections.contains(responseDigest)) {

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2009 Jonas Ådahl, 2011-2014 Florian Schmaus
* Copyright © 2009 Jonas Ådahl, 2011-2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,7 +16,7 @@
*/
package org.jivesoftware.smackx.caps;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Comparator;
@ -749,13 +749,7 @@ public final class EntityCapsManager extends Manager {
// encoded using Base64 as specified in Section 4 of RFC 4648
// (note: the Base64 output MUST NOT include whitespace and MUST set
// padding bits to zero).
byte[] bytes;
try {
bytes = sb.toString().getBytes(StringUtils.UTF8);
}
catch (UnsupportedEncodingException e) {
throw new AssertionError(e);
}
byte[] bytes = sb.toString().getBytes(StandardCharsets.UTF_8);
byte[] digest;
synchronized (md) {
digest = md.digest(bytes);