View Javadoc

1   /*
2    * REPOWEB, repository manager.
3    *
4    * Terms of license - http://opensource.org/licenses/apachepl.php
5    */
6   package org.repoweb.model.jar;
7   import java.io.File;
8   import java.io.IOException;
9   import java.io.InputStream;
10  import java.net.URL;
11  import java.net.URLConnection;
12  import org.apache.commons.logging.Log;
13  import org.apache.commons.logging.LogFactory;
14  import org.repoweb.model.Artifact;
15  import org.repoweb.model.common.AbstractArtifact;
16  /***
17   * Artifact implementation for repository located into jar.
18   */
19  class JArtifact extends AbstractArtifact {
20      private static final Log LOG = LogFactory.getLog(JArtifact.class);
21      private URL _url;
22  
23      JArtifact(URL url) throws BadArtifactFileException {
24          super(new File(url.getPath()));
25          _url = url;
26      }
27  
28      public Artifact getPom() {
29          return null;
30      }
31  
32  
33      public long getLength() {
34          try {
35              URLConnection urlConnection = _url.openConnection();
36              return urlConnection.getContentLength();
37          }
38          catch (IOException error) {
39              LOG.error("Unable to determine artifact length (" + toString() + ")", error);
40              return -1;
41          }
42      }
43  
44  
45      public InputStream getInputStream() throws IOException {
46          URLConnection urlConnection = _url.openConnection();
47          return urlConnection.getInputStream();
48      }
49  }