1 package org.apache.maven.surefire.util.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.surefire.util.NestedRuntimeException;
23
24 import java.io.IOException;
25 import java.io.OutputStream;
26
27 public class StreamUtils
28 {
29 public static void toHex( OutputStream target, Integer i )
30 {
31 if ( i != null )
32 {
33 toHex( target, i.intValue() );
34 }
35 }
36
37
38
39
40
41
42
43 public static void toHex( OutputStream target, int i )
44 {
45 byte[] buf = new byte[32];
46 int charPos = 32;
47 int radix = 1 << 4;
48 int mask = radix - 1;
49 do
50 {
51 buf[--charPos] = (byte) digits[i & mask];
52 i >>>= 4;
53 }
54 while ( i != 0 );
55
56 try
57 {
58 target.write( buf, charPos, ( 32 - charPos ) );
59 } catch (IOException e)
60 {
61 throw new NestedRuntimeException(e);
62 }
63 }
64
65 private final static char[] digits =
66 { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
67 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
68
69
70 }