Skip to content

Commit b207c45

Browse files
committed
[CODEC-276] Reliance on default encoding in MurmurHash2 and MurmurHash3.
Reuse our StringUtils.getBytesUtf8(text).
1 parent f3fe3af commit b207c45

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

src/main/java/org/apache/commons/codec/digest/MurmurHash2.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
package org.apache.commons.codec.digest;
1919

20-
import java.nio.charset.Charset;
21-
import java.nio.charset.StandardCharsets;
20+
import org.apache.commons.codec.binary.StringUtils;
2221

2322
/**
2423
* Implementation of the MurmurHash2 32-bit and 64-bit hash functions.
@@ -51,13 +50,6 @@
5150
*/
5251
public final class MurmurHash2 {
5352

54-
/**
55-
* Default Charset used to convert strings into bytes.
56-
*
57-
* Consider private; package private for tests only.
58-
*/
59-
static final Charset GET_BYTES_CHARSET = StandardCharsets.UTF_8;
60-
6153
// Constants for 32-bit variant
6254
private static final int M32 = 0x5bd1e995;
6355
private static final int R32 = 24;
@@ -154,7 +146,7 @@ public static int hash32(final byte[] data, final int length) {
154146
* @see #hash32(byte[], int, int)
155147
*/
156148
public static int hash32(final String text) {
157-
final byte[] bytes = text.getBytes(GET_BYTES_CHARSET);
149+
final byte[] bytes = StringUtils.getBytesUtf8(text);
158150
return hash32(bytes, bytes.length);
159151
}
160152

@@ -268,7 +260,7 @@ public static long hash64(final byte[] data, final int length) {
268260
* @see #hash64(byte[], int, int)
269261
*/
270262
public static long hash64(final String text) {
271-
final byte[] bytes = text.getBytes(GET_BYTES_CHARSET);
263+
final byte[] bytes = StringUtils.getBytesUtf8(text);
272264
return hash64(bytes, bytes.length);
273265
}
274266

0 commit comments

Comments
 (0)