1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.vfs.internal.attach; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.io.InputStream; |
24 |
|
import java.nio.channels.SeekableByteChannel; |
25 |
|
|
26 |
|
import javax.annotation.concurrent.NotThreadSafe; |
27 |
|
|
28 |
|
import net.java.truecommons.cio.AbstractInputSocket; |
29 |
|
import net.java.truecommons.cio.Entry; |
30 |
|
import net.java.truecommons.cio.IoBuffer; |
31 |
|
import net.java.truecommons.cio.IoSockets; |
32 |
|
import net.java.truecommons.cio.OutputSocket; |
33 |
|
import net.java.truecommons.io.ReadOnlyChannel; |
34 |
|
import net.java.truecommons.shed.BitField; |
35 |
|
import net.java.truevfs.kernel.spec.FsAccessOption; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@NotThreadSafe |
|
|
| 60% |
Uncovered Elements: 6 (15) |
Complexity: 6 |
Complexity Density: 0.55 |
|
44 |
|
public class AttachInputSocket extends AbstractInputSocket<AttachNode> |
45 |
|
{ |
46 |
|
private final AttachNode entry; |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
4 |
AttachInputSocket(BitField<FsAccessOption> options, AttachNode entry)... |
49 |
|
{ |
50 |
4 |
this.entry = entry; |
51 |
|
} |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
0 |
@Override... |
54 |
|
public AttachNode target() |
55 |
|
{ |
56 |
0 |
return entry; |
57 |
|
} |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
2 |
@Override... |
60 |
|
public InputStream stream(final OutputSocket<? extends Entry> peer) throws IOException |
61 |
|
{ |
62 |
2 |
return entry.newInputStream(); |
63 |
|
} |
64 |
|
|
|
|
| 50% |
Uncovered Elements: 4 (8) |
Complexity: 3 |
Complexity Density: 0.38 |
|
65 |
2 |
@Override... |
66 |
|
public SeekableByteChannel channel(final OutputSocket<? extends Entry> peer) throws IOException |
67 |
|
{ |
68 |
2 |
final IoBuffer buffer = entry.getPool().allocate(); |
69 |
2 |
try { |
70 |
2 |
IoSockets.copy(entry.input(), buffer.output()); |
71 |
|
} catch (final Throwable ex) { |
72 |
0 |
try { |
73 |
0 |
buffer.release(); |
74 |
|
} catch (final Throwable ex2) { |
75 |
0 |
ex.addSuppressed(ex2); |
76 |
|
} |
77 |
0 |
throw ex; |
78 |
|
} |
|
|
| 22.2% |
Uncovered Elements: 7 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
79 |
|
final class BufferReadOnlyChannel extends ReadOnlyChannel |
80 |
|
{ |
81 |
|
private boolean closed; |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
2 |
BufferReadOnlyChannel() throws IOException... |
84 |
|
{ |
85 |
2 |
super(buffer.input().channel(peer)); |
86 |
|
} |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
88 |
0 |
@Override... |
89 |
|
public void close() throws IOException |
90 |
|
{ |
91 |
0 |
if (!closed) { |
92 |
0 |
channel.close(); |
93 |
0 |
closed = true; |
94 |
0 |
buffer.release(); |
95 |
|
} |
96 |
|
} |
97 |
|
} |
98 |
2 |
return new BufferReadOnlyChannel(); |
99 |
|
} |
100 |
|
} |