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

File XWikiExtensionFile.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

0
16
5
2
98
60
6
0.38
3.2
2.5
1.2

Classes

Class Line # Actions
XWikiExtensionFile 36 12 0% 4 9
0.440%
XWikiExtensionFile.XWikiExtensionFileInputStream 42 4 0% 2 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

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.extension.repository.xwiki.internal;
21   
22    import java.io.FilterInputStream;
23    import java.io.IOException;
24    import java.io.InputStream;
25   
26    import org.apache.commons.io.IOUtils;
27    import org.apache.http.HttpEntity;
28    import org.apache.http.client.methods.CloseableHttpResponse;
29    import org.xwiki.extension.ExtensionFile;
30    import org.xwiki.extension.ExtensionId;
31   
32    /**
33    * @version $Id: c45223147c2ccd275905cf0a4675e9c3bfabc291 $
34    * @since 4.0M1
35    */
 
36    public class XWikiExtensionFile implements ExtensionFile
37    {
38    private XWikiExtensionRepository repository;
39   
40    private ExtensionId id;
41   
 
42    static class XWikiExtensionFileInputStream extends FilterInputStream
43    {
44    private CloseableHttpResponse response;
45   
 
46  14 toggle public XWikiExtensionFileInputStream(CloseableHttpResponse response) throws IllegalStateException, IOException
47    {
48  14 super(response.getEntity().getContent());
49   
50  14 this.response = response;
51    }
52   
 
53  28 toggle @Override
54    public void close() throws IOException
55    {
56  28 super.close();
57   
58  28 this.response.close();
59    }
60    }
61   
 
62  67 toggle public XWikiExtensionFile(XWikiExtensionRepository repository, ExtensionId id)
63    {
64  67 this.repository = repository;
65  67 this.id = id;
66    }
67   
 
68  0 toggle @Override
69    public long getLength()
70    {
71  0 CloseableHttpResponse response;
72  0 try {
73  0 response =
74    this.repository.getRESTResource(this.repository.getExtensionFileUriBuider(), this.id.getId(), this.id
75    .getVersion().getValue());
76    } catch (IOException e) {
77  0 throw new RuntimeException("Failed to acess extension [" + this + "]", e);
78    }
79   
80  0 HttpEntity entity = response.getEntity();
81   
82  0 try {
83  0 return entity.getContentLength();
84    } finally {
85  0 IOUtils.closeQuietly(response);
86    }
87    }
88   
 
89  14 toggle @Override
90    public InputStream openStream() throws IOException
91    {
92  14 CloseableHttpResponse response =
93    this.repository.getRESTResource(this.repository.getExtensionFileUriBuider(), this.id.getId(), this.id
94    .getVersion().getValue());
95   
96  14 return new XWikiExtensionFileInputStream(response);
97    }
98    }