提交 264666fc 编写于 作者: K kohsuke

added hex dump support

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34828 71c3de6d-444a-0410-be80-ed276b4c234a
上级 8599b90a
package hudson.remoting;
/**
* @author Kohsuke Kawaguchi
*/
public class HexDump {
private static final String CODE = "0123456789abcdef";
public static String toHex(byte[] buf) {
return toHex(buf,0,buf.length);
}
public static String toHex(byte[] buf, int start, int len) {
StringBuilder r = new StringBuilder(len*2);
for (int i=0; i<len; i++) {
byte b = buf[start+i];
r.append(CODE.charAt((b>>4)&15));
r.append(CODE.charAt(b&15));
}
return r.toString();
}
}
package hudson.remoting;
import junit.framework.TestCase;
/**
* @author Kohsuke Kawaguchi
*/
public class HexDumpTest extends TestCase {
public void test1() {
assertEquals("0001ff",HexDump.toHex(new byte[]{0,1,-1}));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册