1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.vfs.internal.attach

File AttachInputSocket.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

2
16
6
2
100
65
9
0.56
2.67
3
1.5

Classes

Class Line # Actions
AttachInputSocket 44 11 0% 6 6
0.660%
AttachInputSocket.BufferReadOnlyChannel 79 5 0% 3 7
0.2222222222.2%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * TrueVFS input socket for the Attach Driver.
39    *
40    * @version $Id: f6feb543de10911ef506b7d4b9129497860a2a7f $
41    * @since 7.4M2
42    */
43    @NotThreadSafe
 
44    public class AttachInputSocket extends AbstractInputSocket<AttachNode>
45    {
46    private final AttachNode entry;
47   
 
48  4 toggle AttachInputSocket(BitField<FsAccessOption> options, AttachNode entry)
49    {
50  4 this.entry = entry;
51    }
52   
 
53  0 toggle @Override
54    public AttachNode target()
55    {
56  0 return entry;
57    }
58   
 
59  2 toggle @Override
60    public InputStream stream(final OutputSocket<? extends Entry> peer) throws IOException
61    {
62  2 return entry.newInputStream();
63    }
64   
 
65  2 toggle @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    }
 
79    final class BufferReadOnlyChannel extends ReadOnlyChannel
80    {
81    private boolean closed;
82   
 
83  2 toggle BufferReadOnlyChannel() throws IOException
84    {
85  2 super(buffer.input().channel(peer));
86    }
87   
 
88  0 toggle @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    }