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.encoder; |
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 |
|
|
|
|
| 88.3% |
Uncovered Elements: 7 (60) |
Complexity: 14 |
Complexity Density: 0.38 |
|
32 |
|
class BcBinaryStringEncoderOutputStream extends FilterOutputStream |
33 |
|
{ |
34 |
|
|
35 |
|
private final int blockSize; |
36 |
|
|
37 |
|
|
38 |
|
private final byte[] oneByte = new byte[1]; |
39 |
|
|
40 |
|
|
41 |
|
private byte[] ofBuf; |
42 |
|
|
43 |
|
|
44 |
|
private int ofLen; |
45 |
|
|
46 |
|
|
47 |
|
private final InternalBinaryStringEncoder encoder; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@param |
53 |
|
@param |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
55 |
6 |
BcBinaryStringEncoderOutputStream(OutputStream outputStream, InternalBinaryStringEncoder encoder)... |
56 |
|
{ |
57 |
6 |
super(outputStream); |
58 |
6 |
this.encoder = encoder; |
59 |
6 |
this.blockSize = encoder.getEncodingBlockSize(); |
60 |
6 |
this.ofBuf = new byte[this.blockSize]; |
61 |
|
} |
62 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
63 |
0 |
@Override... |
64 |
|
public void write(int i) throws IOException |
65 |
|
{ |
66 |
0 |
this.oneByte[0] = (byte) i; |
67 |
0 |
write(this.oneByte, 0, 1); |
68 |
|
} |
69 |
|
|
|
|
| 90.2% |
Uncovered Elements: 4 (41) |
Complexity: 9 |
Complexity Density: 0.36 |
|
70 |
48 |
@Override... |
71 |
|
public void write(byte[] input, int offset, int length) throws IOException |
72 |
|
{ |
73 |
48 |
if ((offset | length | (input.length - (length + offset)) | (offset + length)) < 0) { |
74 |
0 |
throw new IndexOutOfBoundsException(); |
75 |
|
} |
76 |
|
|
77 |
48 |
if (length == 0) { |
78 |
0 |
return; |
79 |
|
} |
80 |
|
|
81 |
48 |
int off = offset; |
82 |
48 |
int len = length; |
83 |
|
|
84 |
|
|
85 |
48 |
if (this.ofLen > 0) { |
86 |
|
|
87 |
20 |
int underflow = this.blockSize - this.ofLen; |
88 |
20 |
if (underflow > len) { |
89 |
8 |
underflow = len; |
90 |
|
} |
91 |
20 |
System.arraycopy(input, off, this.ofBuf, this.ofLen, underflow); |
92 |
20 |
this.ofLen += underflow; |
93 |
20 |
off += underflow; |
94 |
20 |
len -= underflow; |
95 |
|
|
96 |
|
|
97 |
20 |
if (this.ofLen == this.blockSize) { |
98 |
12 |
this.encoder.encode(this.ofBuf, 0, this.blockSize, this.out); |
99 |
12 |
this.ofLen = 0; |
100 |
|
} |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
48 |
if (len > 0) { |
105 |
|
|
106 |
|
|
107 |
36 |
int overflow = len - ((len / this.blockSize) * this.blockSize); |
108 |
36 |
if (overflow > 0) { |
109 |
16 |
System.arraycopy(input, (off + len - overflow), this.ofBuf, 0, overflow); |
110 |
16 |
this.ofLen += overflow; |
111 |
16 |
len -= overflow; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
36 |
if (len > 0) { |
116 |
28 |
this.encoder.encode(input, off, len, this.out); |
117 |
|
} |
118 |
|
} |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
121 |
12 |
@Override... |
122 |
|
public void flush() throws IOException |
123 |
|
{ |
124 |
12 |
if (this.ofLen > 0) { |
125 |
4 |
this.encoder.encode(this.ofBuf, 0, this.ofLen, this.out); |
126 |
4 |
this.ofLen = 0; |
127 |
|
} |
128 |
12 |
this.out.flush(); |
129 |
|
} |
130 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
131 |
6 |
@Override... |
132 |
|
public void close() throws IOException |
133 |
|
{ |
134 |
6 |
flush(); |
135 |
6 |
super.close(); |
136 |
|
} |
137 |
|
} |