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