javeme commented on code in PR #2095:
URL: 
https://github.com/apache/incubator-hugegraph/pull/2095#discussion_r1101532429


##########
hugegraph-core/src/main/java/org/apache/hugegraph/util/StringEncoding.java:
##########
@@ -14,19 +14,22 @@
 
 package org.apache.hugegraph.util;
 
-import java.io.UnsupportedEncodingException;
+import static java.nio.charset.StandardCharsets.UTF_8;

Review Comment:
   don't import static as possible,  import StandardCharsets instead, and can 
define a static final UTF8 = StandardCharsets.UTF_8



##########
hugegraph-core/src/main/java/org/apache/hugegraph/util/StringEncoding.java:
##########
@@ -137,18 +129,23 @@ public static byte[] compress(String value) {
     }
 
     public static byte[] compress(String value, float bufferRatio) {
-        BytesBuffer buf = LZ4Util.compress(encode(value), BLOCK_SIZE,
-                                           bufferRatio);
-        return buf.bytes();
+        try (BytesBuffer buf = LZ4Util.compress(encode(value), BLOCK_SIZE, 
bufferRatio)) {
+            return buf.bytes();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     public static String decompress(byte[] value) {
         return decompress(value, LZ4Util.DEFAULT_BUFFER_RATIO);
     }
 
     public static String decompress(byte[] value, float bufferRatio) {
-        BytesBuffer buf = LZ4Util.decompress(value, BLOCK_SIZE, bufferRatio);
-        return decode(buf.array(), 0, buf.position());
+        try (BytesBuffer buf = LZ4Util.decompress(value, BLOCK_SIZE, 
bufferRatio)) {
+            return decode(buf.array(), 0, buf.position());
+        } catch (IOException e) {

Review Comment:
   seems don't need to catch IOException



##########
hugegraph-core/src/main/java/org/apache/hugegraph/util/StringEncoding.java:
##########
@@ -92,33 +96,21 @@ public static int getAsciiByteLength(String value) {
     }
 
     public static byte[] encode(String value) {
-        try {
-            return value.getBytes("UTF-8");
-        } catch (UnsupportedEncodingException e) {
-            throw new HugeException("Failed to encode string", e);
-        }
+        return value.getBytes(UTF_8);

Review Comment:
   ok



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to