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

File DefaultCoreExtensionFile.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart2.png
81% of files have more coverage

Code metrics

2
9
5
1
89
41
7
0.78
1.8
5
1.4

Classes

Class Line # Actions
DefaultCoreExtensionFile 35 9 0% 7 14
0.12512.5%
 

Contributing tests

This file is covered by 10 tests. .

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.internal.core;
21   
22    import java.io.IOException;
23    import java.io.InputStream;
24    import java.net.URL;
25    import java.net.URLConnection;
26   
27    import org.xwiki.extension.CoreExtensionFile;
28   
29    /**
30    * Default implementation of {@link CoreExtensionFile}.
31    *
32    * @version $Id: 8a338e3bb68a3bed10dc35b9275c5a8b5cde8d51 $
33    * @since 4.0M1
34    */
 
35    public class DefaultCoreExtensionFile implements CoreExtensionFile
36    {
37    /**
38    * @see #getURL()
39    */
40    private URL url;
41   
42    /**
43    * @see #getConnection()
44    */
45    private URLConnection connection;
46   
47    /**
48    * @param url the URL of the core extension
49    */
 
50  35764 toggle public DefaultCoreExtensionFile(URL url)
51    {
52  35764 this.url = url;
53    }
54   
55    /**
56    * @return the URL connection
57    */
 
58  0 toggle private URLConnection getConnection()
59    {
60  0 if (this.connection == null) {
61  0 try {
62  0 this.connection = this.url.openConnection();
63    } catch (IOException e) {
64  0 throw new RuntimeException("Failed to open URL [" + this.url + "]", e);
65    }
66    }
67   
68  0 return this.connection;
69    }
70   
 
71  0 toggle @Override
72    public long getLength()
73    {
74  0 return getConnection().getContentLength();
75    }
76   
 
77  0 toggle @Override
78    public InputStream openStream() throws IOException
79    {
80  0 return getConnection().getInputStream();
81    }
82   
 
83  0 toggle @Override
84    public URL getURL()
85    {
86  0 return this.url;
87    }
88   
89    }