~ubuntu-branches/ubuntu/trusty/ivy/trusty-proposed

« back to all changes in this revision

Viewing changes to src/java/org/apache/ivy/util/url/URLHandler.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2009-03-06 22:04:56 UTC
  • Revision ID: james.westby@ubuntu.com-20090306220456-5v37luqiuqda8ewp
Tags: upstream-2.0.0
ImportĀ upstreamĀ versionĀ 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 *  contributor license agreements.  See the NOTICE file distributed with
 
4
 *  this work for additional information regarding copyright ownership.
 
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 *  (the "License"); you may not use this file except in compliance with
 
7
 *  the License.  You may obtain a copy of the License at
 
8
 *
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 *
 
11
 *  Unless required by applicable law or agreed to in writing, software
 
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
 
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 *  See the License for the specific language governing permissions and
 
15
 *  limitations under the License.
 
16
 *
 
17
 */
 
18
package org.apache.ivy.util.url;
 
19
 
 
20
import java.io.File;
 
21
import java.io.IOException;
 
22
import java.io.InputStream;
 
23
import java.net.URL;
 
24
 
 
25
import org.apache.ivy.util.CopyProgressListener;
 
26
 
 
27
/**
 
28
 * This interface is responsible for handling some URL manipulation (stream opening, downloading,
 
29
 * check reachability, ...).
 
30
 */
 
31
public interface URLHandler {
 
32
    
 
33
    /**
 
34
     * Using the slower REQUEST method for getting the basic URL infos. Use this when getting errors
 
35
     * behind a problematic/special proxy or firewall chain.
 
36
     */
 
37
    public static final int REQUEST_METHOD_GET = 1;
 
38
 
 
39
    /**
 
40
     * Using the faster HEAD method for getting the basic URL infos. Works for most common networks.
 
41
     */
 
42
    public static final int REQUEST_METHOD_HEAD = 2;
 
43
 
 
44
    public static class URLInfo {
 
45
        private long contentLength;
 
46
 
 
47
        private long lastModified;
 
48
 
 
49
        private boolean available;
 
50
 
 
51
        protected URLInfo(boolean available, long contentLength, long lastModified) {
 
52
            this.available = available;
 
53
            this.contentLength = contentLength;
 
54
            this.lastModified = lastModified;
 
55
        }
 
56
 
 
57
        public boolean isReachable() {
 
58
            return available;
 
59
        }
 
60
 
 
61
        public long getContentLength() {
 
62
            return contentLength;
 
63
        }
 
64
 
 
65
        public long getLastModified() {
 
66
            return lastModified;
 
67
        }
 
68
    }
 
69
 
 
70
    public static final URLInfo UNAVAILABLE = new URLInfo(false, 0, 0);
 
71
 
 
72
    /**
 
73
     * Please prefer getURLInfo when several infos are needed.
 
74
     * 
 
75
     * @param url
 
76
     *            the url to check
 
77
     * @return true if the target is reachable
 
78
     */
 
79
    public boolean isReachable(URL url);
 
80
 
 
81
    /**
 
82
     * Please prefer getURLInfo when several infos are needed.
 
83
     * 
 
84
     * @param url
 
85
     *            the url to check
 
86
     * @return true if the target is reachable
 
87
     */
 
88
    public boolean isReachable(URL url, int timeout);
 
89
 
 
90
    /**
 
91
     * Returns the length of the target if the given url is reachable, and without error code in
 
92
     * case of http urls. Please prefer getURLInfo when several infos are needed.
 
93
     * 
 
94
     * @param url
 
95
     *            the url to check
 
96
     * @return the length of the target if available, 0 if not reachable
 
97
     */
 
98
    public long getContentLength(URL url);
 
99
 
 
100
    /**
 
101
     * Returns the length of the target if the given url is reachable, and without error code in
 
102
     * case of http urls.
 
103
     * 
 
104
     * @param url
 
105
     *            the url to check
 
106
     * @param timeout
 
107
     *            the maximum time before considering an url is not reachable a timeout of zero
 
108
     *            indicates no timeout
 
109
     * @return the length of the target if available, 0 if not reachable
 
110
     */
 
111
    public long getContentLength(URL url, int timeout);
 
112
 
 
113
    /**
 
114
     * Please prefer getURLInfo when several infos are needed.
 
115
     * 
 
116
     * @param url
 
117
     *            the url to check
 
118
     * @return last modified timestamp of the given url
 
119
     */
 
120
    public long getLastModified(URL url);
 
121
 
 
122
    /**
 
123
     * Please prefer getURLInfo when several infos are needed.
 
124
     * 
 
125
     * @param url
 
126
     *            the url to check
 
127
     * @return last modified timestamp of the given url
 
128
     */
 
129
    public long getLastModified(URL url, int timeout);
 
130
 
 
131
    /**
 
132
     * Returns the URLInfo of the given url or a {@link #UNAVAILABLE} instance,
 
133
     * if the url is not reachable.
 
134
     * 
 
135
     * @param  url  The url from which information is retrieved.
 
136
     * @return  The URLInfo extracted from the given url, or {@link #UNAVAILABLE} when
 
137
     *          the url is not available.
 
138
     */
 
139
    public URLInfo getURLInfo(URL url);
 
140
 
 
141
    /**
 
142
     * never returns null, return UNAVAILABLE when url is not reachable
 
143
     * 
 
144
     * @param  url  The url from which information is retrieved.
 
145
     * @param  timeout  The timeout in milliseconds.
 
146
     * @return  The URLInfo extracted from the given url, or {@link #UNAVAILABLE} when
 
147
     *          the url is not available.
 
148
     */
 
149
    public URLInfo getURLInfo(URL url, int timeout);
 
150
 
 
151
    public InputStream openStream(URL url) throws IOException;
 
152
 
 
153
    public void download(URL src, File dest, CopyProgressListener l) throws IOException;
 
154
 
 
155
    public void upload(File src, URL dest, CopyProgressListener l) throws IOException;
 
156
    
 
157
    public void setRequestMethod(int requestMethod);
 
158
}