-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from chanchiem/testjdk
Add testing for JDK11 (#77)
- Loading branch information
Showing
11 changed files
with
82 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/utils/ByteUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.amazonaws.xray.utils; | ||
|
||
public class ByteUtils { | ||
static final String HEXES = "0123456789ABCDEF"; | ||
|
||
/** | ||
* ref: https://stackoverflow.com/questions/9655181/how-to-convert-a-byte-array-to-a-hex-string-in-java | ||
* | ||
* Converts the input byte array into a hexadecimal string. | ||
* @param raw - Byte array | ||
* @return String - Hexadecimal representation of the byte array. | ||
*/ | ||
public static String byteArrayToHexString( byte [] raw ) { | ||
if ( raw == null ) { | ||
return null; | ||
} | ||
final StringBuilder hex = new StringBuilder( 2 * raw.length ); | ||
for ( final byte b : raw ) { | ||
hex.append(HEXES.charAt((b & 0xF0) >> 4)) | ||
.append(HEXES.charAt((b & 0x0F))); | ||
} | ||
return hex.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
aws-xray-recorder-sdk-core/src/test/java/com/amazonaws/xray/utils/ByteUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.amazonaws.xray.utils; | ||
|
||
import org.junit.FixMethodOrder; | ||
import org.junit.Test; | ||
import org.junit.runners.MethodSorters; | ||
|
||
@FixMethodOrder(MethodSorters.JVM) | ||
public class ByteUtilsTest { | ||
|
||
@Test | ||
public void testHexString() { | ||
byte[] zeroArray = new byte[16]; | ||
assert ByteUtils.byteArrayToHexString(zeroArray).contentEquals("00000000000000000000000000000000"); | ||
|
||
byte[] emptyArray = {}; | ||
assert ByteUtils.byteArrayToHexString(emptyArray).contentEquals(""); | ||
|
||
byte[] zeroByte = {(byte) 0x00}; | ||
assert ByteUtils.byteArrayToHexString(zeroByte).contentEquals("00"); | ||
|
||
byte[] fullByte = {(byte) 0xFF}; | ||
assert ByteUtils.byteArrayToHexString(fullByte).contentEquals("FF"); | ||
|
||
byte[] leadingZero = {(byte) 0x0F}; | ||
assert ByteUtils.byteArrayToHexString(leadingZero).contentEquals("0F"); | ||
|
||
byte[] longLeadingZero = {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x11}; | ||
assert ByteUtils.byteArrayToHexString(longLeadingZero).contentEquals("00000000000011"); | ||
|
||
byte[] trailingZero = {(byte) 0x11, (byte) 0x00}; | ||
assert ByteUtils.byteArrayToHexString(trailingZero).contentEquals("1100"); | ||
|
||
byte[] longTrailingZero = new byte[16]; | ||
longTrailingZero[0] = (byte) 0xFF; | ||
assert ByteUtils.byteArrayToHexString(longTrailingZero).contentEquals("FF000000000000000000000000000000"); | ||
|
||
byte[] basicArray = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0x00, (byte) 0xFF, (byte) 0xF0, (byte) 0x0F, (byte) 0xFF}; | ||
assert ByteUtils.byteArrayToHexString(basicArray).contentEquals("FFFFFF00FFF00FFF"); | ||
|
||
byte[] basicVariedArray = {(byte) 0x82, (byte) 0xF2, (byte) 0xAB, (byte) 0xA4, (byte) 0xDE, (byte) 0x15, (byte) 0x19, (byte) 0x11}; | ||
assert ByteUtils.byteArrayToHexString(basicVariedArray).contentEquals("82F2ABA4DE151911"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters