diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-01-07 16:16:12 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-01-07 16:16:12 +1300 |
commit | 68e178c43d8619b8b13aa78828c75e788d4d2621 (patch) | |
tree | 178144cd8e08202139f0023000696af051c30156 | |
parent | 17b247bb7d55be49ef1ca24465e81c350ca7b49c (diff) | |
download | trackermap-server-68e178c43d8619b8b13aa78828c75e788d4d2621.tar.gz trackermap-server-68e178c43d8619b8b13aa78828c75e788d4d2621.tar.bz2 trackermap-server-68e178c43d8619b8b13aa78828c75e788d4d2621.zip |
Add hex conversion method
-rw-r--r-- | src/org/traccar/helper/ChannelBufferTools.java | 14 | ||||
-rw-r--r-- | test/org/traccar/helper/ChannelBufferToolsTest.java | 6 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java index ef2ebc313..0de07610d 100644 --- a/src/org/traccar/helper/ChannelBufferTools.java +++ b/src/org/traccar/helper/ChannelBufferTools.java @@ -17,6 +17,7 @@ package org.traccar.helper; import java.util.Formatter; import org.jboss.netty.buffer.ChannelBuffer; +import org.traccar.protocol.IntellitracFrameDecoder; /** * ChannelBuffer helper methods @@ -130,4 +131,17 @@ public class ChannelBufferTools { } return out; } + + /** + * Convert hex string to byte array + */ + public static byte[] convertHexString(String in) { + int count = in.length() / 2; + byte[] out = new byte[count]; + for (int i = 0; i < count; i++) { + out[i] = Integer.valueOf(in.substring(i * 2, (i + 1) * 2), 16).byteValue(); + } + return out; + } + } diff --git a/test/org/traccar/helper/ChannelBufferToolsTest.java b/test/org/traccar/helper/ChannelBufferToolsTest.java index 792770dab..67c58058b 100644 --- a/test/org/traccar/helper/ChannelBufferToolsTest.java +++ b/test/org/traccar/helper/ChannelBufferToolsTest.java @@ -31,4 +31,10 @@ public class ChannelBufferToolsTest { result = Long.valueOf(result).toString(); assertEquals("1903", result); } + + @Test + public void convertHexStringTest() { + assertArrayEquals(ChannelBufferTools.convertHexString("1234"), new byte[] {0x12,0x34}); + } + } |