1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
34 |
|
@since |
35 |
|
|
|
|
| 40% |
Uncovered Elements: 9 (15) |
Complexity: 4 |
Complexity Density: 0.33 |
|
36 |
|
public class XWikiExtensionFile implements ExtensionFile |
37 |
|
{ |
38 |
|
private XWikiExtensionRepository repository; |
39 |
|
|
40 |
|
private ExtensionId id; |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
42 |
|
static class XWikiExtensionFileInputStream extends FilterInputStream |
43 |
|
{ |
44 |
|
private CloseableHttpResponse response; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
46 |
14 |
public XWikiExtensionFileInputStream(CloseableHttpResponse response) throws IllegalStateException, IOException... |
47 |
|
{ |
48 |
14 |
super(response.getEntity().getContent()); |
49 |
|
|
50 |
14 |
this.response = response; |
51 |
|
} |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
53 |
28 |
@Override... |
54 |
|
public void close() throws IOException |
55 |
|
{ |
56 |
28 |
super.close(); |
57 |
|
|
58 |
28 |
this.response.close(); |
59 |
|
} |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
62 |
67 |
public XWikiExtensionFile(XWikiExtensionRepository repository, ExtensionId id)... |
63 |
|
{ |
64 |
67 |
this.repository = repository; |
65 |
67 |
this.id = id; |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
68 |
0 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
89 |
14 |
@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 |
|
} |