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 | |
|
23 | |
|
24 | |
|
25 | |
public class ByteBuffer |
26 | |
{ |
27 | |
private final byte[] data; |
28 | |
|
29 | |
private int position; |
30 | |
|
31 | |
public ByteBuffer( int length ) |
32 | 4 | { |
33 | 4 | this.data = new byte[length]; |
34 | 4 | } |
35 | |
|
36 | |
public ByteBuffer( byte[] buf, int off, int len ) |
37 | 0 | { |
38 | 0 | this.data = new byte[len]; |
39 | 0 | append( buf, off, len ); |
40 | 0 | } |
41 | |
|
42 | |
|
43 | |
public void append( char chararcter ) |
44 | |
{ |
45 | 8 | data[position++] = (byte) chararcter; |
46 | 8 | } |
47 | |
|
48 | |
public void append( byte chararcter ) |
49 | |
{ |
50 | 3 | data[position++] = chararcter; |
51 | 3 | } |
52 | |
|
53 | |
private static final byte comma = (byte) ','; |
54 | |
|
55 | |
public void comma() |
56 | |
{ |
57 | 4 | data[position++] = comma; |
58 | 4 | } |
59 | |
|
60 | |
|
61 | |
public void advance( int i ) |
62 | |
{ |
63 | 2 | position += i; |
64 | 2 | } |
65 | |
|
66 | |
public void append( Integer integer ) |
67 | |
{ |
68 | 2 | toHex( integer.intValue() ); |
69 | 2 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
private void toHex( int i ) |
77 | |
{ |
78 | 2 | byte[] buf = new byte[32]; |
79 | 2 | int charPos = 32; |
80 | 2 | int radix = 1 << 4; |
81 | 2 | int mask = radix - 1; |
82 | |
do |
83 | |
{ |
84 | 2 | buf[--charPos] = (byte) digits[i & mask]; |
85 | 2 | i >>>= 4; |
86 | |
} |
87 | 2 | while ( i != 0 ); |
88 | |
|
89 | 2 | append( buf, charPos, ( 32 - charPos ) ); |
90 | 2 | } |
91 | |
|
92 | 1 | private final static char[] digits = |
93 | |
{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', |
94 | |
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; |
95 | |
|
96 | |
|
97 | |
public byte[] getData() |
98 | |
{ |
99 | 4 | return data; |
100 | |
} |
101 | |
|
102 | |
public int getlength() |
103 | |
{ |
104 | 5 | return position; |
105 | |
} |
106 | |
|
107 | |
public String toString() |
108 | |
{ |
109 | 2 | return new String( data, 0, position ); |
110 | |
} |
111 | |
|
112 | |
public static byte[] copy( byte[] src1, int off1, int len1 ) |
113 | |
{ |
114 | 0 | byte[] combined = new byte[len1]; |
115 | 0 | int pos = 0; |
116 | 0 | for ( int i = off1; i < off1 + len1; i++ ) |
117 | |
{ |
118 | 0 | combined[pos++] = src1[i]; |
119 | |
} |
120 | 0 | return combined; |
121 | |
} |
122 | |
|
123 | |
void append( byte[] src1, int off1, int len1 ) |
124 | |
{ |
125 | 4 | for ( int i = off1; i < off1 + len1; i++ ) |
126 | |
{ |
127 | 2 | data[position++] = src1[i]; |
128 | |
} |
129 | 2 | } |
130 | |
|
131 | |
public static byte[] join( byte[] src1, int off1, int len1, byte[] src2, int off2, int len2 ) |
132 | |
{ |
133 | 1 | byte[] combined = new byte[len1 + len2]; |
134 | 1 | int pos = 0; |
135 | 4 | for ( int i = off1; i < off1 + len1; i++ ) |
136 | |
{ |
137 | 3 | combined[pos++] = src1[i]; |
138 | |
} |
139 | 3 | for ( int i = off2; i < off2 + len2; i++ ) |
140 | |
{ |
141 | 2 | combined[pos++] = src2[i]; |
142 | |
} |
143 | 1 | return combined; |
144 | |
} |
145 | |
|
146 | |
} |