directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [2/2] directory-kerberos git commit: Consolidating common utils
Date Tue, 13 Jan 2015 00:01:45 GMT
Consolidating common utils


Project: http://git-wip-us.apache.org/repos/asf/directory-kerberos/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerberos/commit/b7d41822
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerberos/tree/b7d41822
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerberos/diff/b7d41822

Branch: refs/heads/master
Commit: b7d4182295a824e98b1ace36804502ddfb2e009a
Parents: c58ed0e
Author: Drankye <drankye@gmail.com>
Authored: Tue Jan 13 08:00:53 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Tue Jan 13 08:00:53 2015 +0800

----------------------------------------------------------------------
 contrib/haox-util/pom.xml                       | 18 +++++++++
 .../src/main/java/org/haox/util/HexUtil.java    | 39 ++++++++++++++++++++
 2 files changed, 57 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/b7d41822/contrib/haox-util/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/haox-util/pom.xml b/contrib/haox-util/pom.xml
new file mode 100644
index 0000000..c3e59a9
--- /dev/null
+++ b/contrib/haox-util/pom.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <artifactId>contrib</artifactId>
+    <groupId>org.haox</groupId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>haox-util</artifactId>
+
+  <name>Haox Util</name>
+  <description>Haox common util, without any 3rd party dependency</description>
+
+  <dependencies>
+  </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/b7d41822/contrib/haox-util/src/main/java/org/haox/util/HexUtil.java
----------------------------------------------------------------------
diff --git a/contrib/haox-util/src/main/java/org/haox/util/HexUtil.java b/contrib/haox-util/src/main/java/org/haox/util/HexUtil.java
new file mode 100644
index 0000000..f8e06f9
--- /dev/null
+++ b/contrib/haox-util/src/main/java/org/haox/util/HexUtil.java
@@ -0,0 +1,39 @@
+package org.haox.util;
+
+public class HexUtil {
+
+    final static String HEX_CHARS_STR = "0123456789ABCDEF";
+    final static char[] HEX_CHARS = HEX_CHARS_STR.toCharArray();
+
+    /**
+     * Convert bytes into format as:
+     * 02020080
+     */
+    public static String bytesToHex(byte[] bytes) {
+        int len = bytes.length * 2;
+        char[] hexChars = new char[len];
+        for ( int j = 0; j < bytes.length; j++ ) {
+            int v = bytes[j] & 0xFF;
+            hexChars[j * 2] = HEX_CHARS[v >>> 4];
+            hexChars[j * 2 + 1] = HEX_CHARS[v & 0x0F];
+        }
+
+        return new String(hexChars);
+    }
+
+    /**
+     * Convert hex string like follows into byte array
+     * 02020080
+     */
+    public static byte[] hex2bytes(String hexString) {
+        hexString = hexString.toUpperCase();
+        int len = hexString.length() / 2;
+        byte[] bytes = new byte[len];
+        char[] hexChars = hexString.toCharArray();
+        for (int i = 0, j = 0; i < len; ++i) {
+            bytes[i] = (byte) ((HEX_CHARS_STR.indexOf(hexChars[j++]) << 4) + HEX_CHARS_STR.indexOf(hexChars[j++]));
+        }
+
+        return bytes;
+    }
+}


Mime
View raw message