Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StreamUtils |
|
| 3.0;3 |
1 | package org.apache.maven.surefire.util.internal; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import org.apache.maven.surefire.util.NestedRuntimeException; | |
23 | ||
24 | import java.io.IOException; | |
25 | import java.io.OutputStream; | |
26 | ||
27 | 0 | public class StreamUtils |
28 | { | |
29 | public static void toHex( OutputStream target, Integer i ) | |
30 | { | |
31 | 0 | if ( i != null ) |
32 | { | |
33 | 0 | toHex( target, i.intValue() ); |
34 | } | |
35 | 0 | } |
36 | ||
37 | /** | |
38 | * Convert the integer to an unsigned number. | |
39 | * | |
40 | * @param target The stream that will receive the encoded value | |
41 | * @param i the value | |
42 | */ | |
43 | public static void toHex( OutputStream target, int i ) | |
44 | { | |
45 | 0 | byte[] buf = new byte[32]; |
46 | 0 | int charPos = 32; |
47 | 0 | int radix = 1 << 4; |
48 | 0 | int mask = radix - 1; |
49 | do | |
50 | { | |
51 | 0 | buf[--charPos] = (byte) digits[i & mask]; |
52 | 0 | i >>>= 4; |
53 | } | |
54 | 0 | while ( i != 0 ); |
55 | ||
56 | try | |
57 | { | |
58 | 0 | target.write( buf, charPos, ( 32 - charPos ) ); |
59 | 0 | } catch (IOException e) |
60 | { | |
61 | 0 | throw new NestedRuntimeException(e); |
62 | 0 | } |
63 | 0 | } |
64 | ||
65 | 0 | 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 | } |