KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > url > URLHandler


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy.url;
7
8 import java.io.File JavaDoc;
9 import java.io.IOException JavaDoc;
10 import java.io.InputStream JavaDoc;
11 import java.net.URL JavaDoc;
12
13 import fr.jayasoft.ivy.util.CopyProgressListener;
14
15 /**
16  * This interface is responsible for handling some URL manipulation
17  * (stream opening, downloading, check reachability, ...).
18  *
19  * @author Xavier Hanin
20  *
21  */

22 public interface URLHandler {
23     public static class URLInfo {
24         private long _contentLength;
25         private long _lastModified;
26         private boolean _available;
27         
28         protected URLInfo(boolean available, long contentLength, long lastModified) {
29             _available = available;
30             _contentLength = contentLength;
31             _lastModified = lastModified;
32         }
33         public boolean isReachable() {
34             return _available;
35         }
36         public long getContentLength() {
37             return _contentLength;
38         }
39         public long getLastModified() {
40             return _lastModified;
41         }
42     }
43     public static final URLInfo UNAVAILABLE = new URLInfo(false, 0,0);
44     
45     /**
46      * Please prefer getURLInfo when several infos are needed.
47      * @param url the url to check
48      * @return true if the target is reachable
49      */

50     public boolean isReachable(URL JavaDoc url);
51     /**
52      * Please prefer getURLInfo when several infos are needed.
53      * @param url the url to check
54      * @return true if the target is reachable
55      */

56     public boolean isReachable(URL JavaDoc url, int timeout);
57     /**
58      * Returns the length of the target if the given url is reachable, and without
59      * error code in case of http urls.
60      * Please prefer getURLInfo when several infos are needed.
61      * @param url the url to check
62      * @return the length of the target if available, 0 if not reachable
63      */

64     public long getContentLength(URL JavaDoc url);
65     /**
66      * Returns the length of the target if the given url is reachable, and without
67      * error code in case of http urls.
68      * @param url the url to check
69      * @param timeout the maximum time before considering an url is not reachable
70      * a timeout of zero indicates no timeout
71      * @return the length of the target if available, 0 if not reachable
72      */

73     public long getContentLength(URL JavaDoc url, int timeout);
74     
75     /**
76      * Please prefer getURLInfo when several infos are needed.
77      * @param url the url to check
78      * @return last modified timestamp of the given url
79      */

80     public long getLastModified(URL JavaDoc url);
81     /**
82      * Please prefer getURLInfo when several infos are needed.
83      * @param url the url to check
84      * @return last modified timestamp of the given url
85      */

86     public long getLastModified(URL JavaDoc url, int timeout);
87     
88     /**
89      * never returns null, return UNAVAILABLE when url is not reachable
90      * @param url
91      * @return
92      */

93     public URLInfo getURLInfo(URL JavaDoc url);
94     /**
95      * never returns null, return UNAVAILABLE when url is not reachable
96      * @param url
97      * @return
98      */

99     public URLInfo getURLInfo(URL JavaDoc url, int timeout);
100     
101     public InputStream JavaDoc openStream(URL JavaDoc url) throws IOException JavaDoc;
102     public void download(URL JavaDoc src, File JavaDoc dest, CopyProgressListener l) throws IOException JavaDoc;
103 }
104
Popular Tags