1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.internal; |
21 |
|
|
22 |
|
import java.io.FilterOutputStream; |
23 |
|
import java.io.IOException; |
24 |
|
import java.io.OutputStream; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
@version |
30 |
|
@since |
31 |
|
|
|
|
| 86.8% |
Uncovered Elements: 5 (38) |
Complexity: 9 |
Complexity Density: 0.39 |
|
32 |
|
public class LineWrapperOutputStream extends FilterOutputStream |
33 |
|
{ |
34 |
|
|
35 |
|
private static final byte[] NEWLINE = System.getProperty("line.separator", "\n").getBytes(); |
36 |
|
|
37 |
|
|
38 |
|
private byte[] oneByte = new byte[1]; |
39 |
|
|
40 |
|
|
41 |
|
private final int wrapAt; |
42 |
|
|
43 |
|
|
44 |
|
private int count; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@param |
50 |
|
@param |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
52 |
13 |
public LineWrapperOutputStream(OutputStream outputStream, int wrapAt)... |
53 |
|
{ |
54 |
13 |
super(outputStream); |
55 |
13 |
this.wrapAt = wrapAt; |
56 |
13 |
this.count = 0; |
57 |
|
} |
58 |
|
|
|
|
| 83.3% |
Uncovered Elements: 5 (30) |
Complexity: 7 |
Complexity Density: 0.39 |
|
59 |
2266 |
@Override... |
60 |
|
public void write(byte[] bytes, int offset, int length) throws IOException |
61 |
|
{ |
62 |
2266 |
if ((offset | length | (bytes.length - (length + offset)) | (offset + length)) < 0) { |
63 |
0 |
throw new IndexOutOfBoundsException(); |
64 |
|
} |
65 |
|
|
66 |
2266 |
if (length > 0) { |
67 |
2266 |
if (this.count + length >= this.wrapAt) { |
68 |
37 |
int off = offset; |
69 |
37 |
int len = length; |
70 |
37 |
int curlen = this.wrapAt - this.count; |
71 |
37 |
do { |
72 |
37 |
this.out.write(bytes, off, curlen); |
73 |
37 |
this.out.write(NEWLINE, 0, NEWLINE.length); |
74 |
37 |
off += curlen; |
75 |
37 |
len -= curlen; |
76 |
37 |
curlen = (len > this.wrapAt) ? this.wrapAt : len; |
77 |
37 |
} while (curlen == this.wrapAt); |
78 |
37 |
if (curlen > 0) { |
79 |
2 |
this.out.write(bytes, off, curlen); |
80 |
|
} |
81 |
37 |
this.count = curlen; |
82 |
|
} else { |
83 |
2229 |
this.count += length; |
84 |
2229 |
this.out.write(bytes, offset, length); |
85 |
|
} |
86 |
|
} |
87 |
|
} |
88 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
89 |
2257 |
@Override... |
90 |
|
public void write(int i) throws IOException |
91 |
|
{ |
92 |
2257 |
this.oneByte[0] = (byte) i; |
93 |
2257 |
write(this.oneByte, 0, 1); |
94 |
|
} |
95 |
|
} |