Skip to content

Commit 94e205c

Browse files
author
Andrew Or
committed
Use netty Unpooled
1 parent 85202a5 commit 94e205c

File tree

1 file changed

+3
-2
lines changed
  • network/common/src/main/java/org/apache/spark/network/util

1 file changed

+3
-2
lines changed

network/common/src/main/java/org/apache/spark/network/util/JavaUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import com.google.common.io.Closeables;
3131
import com.google.common.base.Charsets;
32+
import io.netty.buffer.Unpooled;
3233
import org.slf4j.Logger;
3334
import org.slf4j.LoggerFactory;
3435

@@ -83,14 +84,14 @@ public static int nonNegativeHash(Object obj) {
8384
* converted back to the same string through {@link #bytesToString(ByteBuffer)}.
8485
*/
8586
public static ByteBuffer stringToBytes(String s) {
86-
return ByteBuffer.wrap(s.getBytes(Charsets.UTF_8));
87+
return Unpooled.wrappedBuffer(s.getBytes(Charsets.UTF_8)).nioBuffer();
8788
}
8889

8990
/**
9091
* Convert the given byte buffer to a string. The resulting string can be
9192
* converted back to the same byte buffer through {@link #stringToBytes(String)}.
9293
*/
9394
public static String bytesToString(ByteBuffer b) {
94-
return new String(b.array(), Charsets.UTF_8);
95+
return Unpooled.wrappedBuffer(b).toString(Charsets.UTF_8);
9596
}
9697
}

0 commit comments

Comments
 (0)