add Bytes.toHex() method (#35)

Change-Id: I613cf44728b347634bda726c3376a6fe1f4d4b2f
This commit is contained in:
Jermy Li 2019-08-15 17:20:25 +08:00 committed by zhoney
parent cc463411ea
commit f8e65f83bd
5 changed files with 22 additions and 3 deletions

View File

@ -1,7 +1,7 @@
language: java
jdk:
- oraclejdk8
- openjdk8
install: mvn compile -Dmaven.javadoc.skip=true

View File

@ -6,7 +6,7 @@
<groupId>com.baidu.hugegraph</groupId>
<artifactId>hugegraph-common</artifactId>
<version>1.6.11</version>
<version>1.6.12</version>
<name>hugegraph-common</name>
<url>https://github.com/hugegraph/hugegraph-common</url>

View File

@ -85,6 +85,10 @@ public final class Bytes {
return Arrays.equals(bytes1, bytes2);
}
public static String toHex(byte b) {
return toHex(new byte[]{b});
}
public static String toHex(byte[] bytes) {
return new String(Hex.encodeHex(bytes));
}

View File

@ -27,5 +27,5 @@ public class CommonVersion {
// The second parameter of Version.of() is for all-in-one JAR
public static final Version VERSION = Version.of(CommonVersion.class,
"1.6.11");
"1.6.12");
}

View File

@ -137,6 +137,21 @@ public class BytesTest extends BaseUnitTest {
Assert.assertEquals(-1, Bytes.indexOf(b(""), (byte) '0'));
}
@Test
public void testByteToHex() {
byte value = 0;
Assert.assertEquals("00", Bytes.toHex(value));
value = 127;
Assert.assertEquals("7f", Bytes.toHex(value));
value = -128;
Assert.assertEquals("80", Bytes.toHex(value));
value = -1;
Assert.assertEquals("ff", Bytes.toHex(value));
}
@Test
public void testBytesToHex() {
int value = 0x0103807f;