StandardCharsets can be used
Reports methods and constructors where constant charset String literal is used (like "UTF-8") which could be replaced with a predefined Charset object like StandardCharsets.UTF_8. This may work a little bit faster, because charset lookup becomes unnecessary. Also catching UnsupportedEncodingException may become unnecessary as well. In this case the catch block will be removed automatically.
This commit is contained in:
@@ -733,11 +733,7 @@ public class BCrypt {
|
||||
public static String hashpw(String password, String salt) {
|
||||
byte passwordb[];
|
||||
|
||||
try {
|
||||
passwordb = password.getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException uee) {
|
||||
throw new AssertionError("UTF-8 is not supported");
|
||||
}
|
||||
passwordb = password.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
return hashpw(passwordb, salt);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.CharacterCodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* UTF-8 Charset encoder/decoder.
|
||||
@@ -28,7 +29,7 @@ import java.nio.charset.Charset;
|
||||
* @author Luke Taylor
|
||||
*/
|
||||
public final class Utf8 {
|
||||
private static final Charset CHARSET = Charset.forName("UTF-8");
|
||||
private static final Charset CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* Get the bytes of the String in UTF-8 encoded form.
|
||||
|
||||
Reference in New Issue
Block a user