Skip to content

Commit 4355c41

Browse files
authored
Merge pull request #526 from esirkova/master
Drop dependency on jaxb for converting binary arrays to hex
2 parents 3de7373 + ef87dd5 commit 4355c41

File tree

6 files changed

+47
-24
lines changed

6 files changed

+47
-24
lines changed

java/amazon-kinesis-producer/pom.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,6 @@
104104
<version>4.13.2</version>
105105
<scope>test</scope>
106106
</dependency>
107-
<dependency>
108-
<groupId>javax.xml.bind</groupId>
109-
<artifactId>jaxb-api</artifactId>
110-
<version>2.3.1</version>
111-
</dependency>
112-
<dependency>
113-
<groupId>com.sun.xml.bind</groupId>
114-
<artifactId>jaxb-core</artifactId>
115-
<version>2.3.0.1</version>
116-
</dependency>
117-
<dependency>
118-
<groupId>com.sun.xml.bind</groupId>
119-
<artifactId>jaxb-impl</artifactId>
120-
<version>2.3.7</version>
121-
</dependency>
122107
<dependency>
123108
<groupId>org.mock-server</groupId>
124109
<artifactId>mockserver-netty-no-dependencies</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.amazonaws.services.kinesis.producer;
2+
3+
public class BinaryToHexConverter {
4+
5+
private static final BinaryToHexConverter INSTANCE = new BinaryToHexConverter();
6+
private static final char[] HEX_CODE = "0123456789ABCDEF".toCharArray();
7+
8+
/**
9+
* Converts an array of bytes into a hex string.
10+
*
11+
* @param data An array of bytes
12+
* @return A string containing a lexical representation of xsd:hexBinary
13+
* @throws IllegalArgumentException if {@code data} is null.
14+
*/
15+
public static String convert(byte[] data) {
16+
return INSTANCE.convertToHex(data);
17+
}
18+
19+
private String convertToHex(byte[] data) {
20+
StringBuilder r = new StringBuilder(data.length * 2);
21+
for (byte b : data) {
22+
r.append(HEX_CODE[(b >> 4) & 0xF]);
23+
r.append(HEX_CODE[(b & 0xF)]);
24+
}
25+
return r.toString();
26+
}
27+
28+
}

java/amazon-kinesis-producer/src/main/java/com/amazonaws/services/kinesis/producer/Daemon.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.slf4j.Logger;
2828
import org.slf4j.LoggerFactory;
2929

30-
import javax.xml.bind.DatatypeConverter;
3130
import java.io.File;
3231
import java.io.IOException;
3332
import java.io.OutputStream;
@@ -582,6 +581,6 @@ private static Messages.Message makeSetCredentialsMessage(AWSCredentialsProvider
582581
}
583582

584583
private static String protobufToHex(com.google.protobuf.Message msg) {
585-
return DatatypeConverter.printHexBinary(msg.toByteArray());
584+
return BinaryToHexConverter.convert(msg.toByteArray());
586585
}
587-
}
586+
}

java/amazon-kinesis-producer/src/main/java/com/amazonaws/services/kinesis/producer/HashedFileCopier.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import java.security.MessageDigest;
2626
import java.util.Arrays;
2727

28-
import javax.xml.bind.DatatypeConverter;
29-
3028
import org.apache.commons.io.IOUtils;
3129
import org.slf4j.Logger;
3230
import org.slf4j.LoggerFactory;
@@ -53,7 +51,7 @@ public static File copyFileFrom(InputStream sourceData, File destinationDirector
5351
digestOutputStream.close();
5452
byte[] digest = digestOutputStream.getMessageDigest().digest();
5553
log.debug("Calculated digest of new file: {}", Arrays.toString(digest));
56-
String digestHex = DatatypeConverter.printHexBinary(digest);
54+
String digestHex = BinaryToHexConverter.convert(digest);
5755
File finalFile = new File(destinationDirectory, String.format(fileNameFormat, digestHex));
5856
File lockFile = new File(destinationDirectory, String.format(fileNameFormat + LOCK_SUFFIX, digestHex));
5957
log.debug("Preparing to check and copy {} to {}", tempFile.getAbsolutePath(), finalFile.getAbsolutePath());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.amazonaws.services.kinesis.producer;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
7+
public class BinaryToHexConverterTest {
8+
9+
@Test
10+
public void testConvert() {
11+
byte[] bytes = {0, 1, 2, 3, 124, 125, 126, 127};
12+
assertEquals("000102037C7D7E7F", BinaryToHexConverter.convert(bytes));
13+
}
14+
15+
}

java/amazon-kinesis-producer/src/test/java/com/amazonaws/services/kinesis/producer/HashedFileCopierTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.security.DigestInputStream;
2828
import java.security.MessageDigest;
2929

30-
import javax.xml.bind.DatatypeConverter;
31-
3230
import org.apache.commons.io.IOUtils;
3331
import org.junit.After;
3432
import org.junit.Before;
@@ -150,7 +148,7 @@ private File makeTestFile() throws Exception {
150148
}
151149

152150
private String hexDigestForTestData() throws Exception {
153-
return DatatypeConverter.printHexBinary(hashForTestData());
151+
return BinaryToHexConverter.convert(hashForTestData());
154152
}
155153

156154
private byte[] testDataBytes() throws Exception {

0 commit comments

Comments
 (0)