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
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.ivy.util.url;
21
import java.io.IOException;
22
import java.io.InputStream;
25
import org.apache.ivy.util.CopyProgressListener;
28
* This interface is responsible for handling some URL manipulation (stream opening, downloading,
29
* check reachability, ...).
31
public interface URLHandler {
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.
37
public static final int REQUEST_METHOD_GET = 1;
40
* Using the faster HEAD method for getting the basic URL infos. Works for most common networks.
42
public static final int REQUEST_METHOD_HEAD = 2;
44
public static class URLInfo {
45
private long contentLength;
47
private long lastModified;
49
private boolean available;
51
protected URLInfo(boolean available, long contentLength, long lastModified) {
52
this.available = available;
53
this.contentLength = contentLength;
54
this.lastModified = lastModified;
57
public boolean isReachable() {
61
public long getContentLength() {
65
public long getLastModified() {
70
public static final URLInfo UNAVAILABLE = new URLInfo(false, 0, 0);
73
* Please prefer getURLInfo when several infos are needed.
77
* @return true if the target is reachable
79
public boolean isReachable(URL url);
82
* Please prefer getURLInfo when several infos are needed.
86
* @return true if the target is reachable
88
public boolean isReachable(URL url, int timeout);
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.
96
* @return the length of the target if available, 0 if not reachable
98
public long getContentLength(URL url);
101
* Returns the length of the target if the given url is reachable, and without error code in
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
111
public long getContentLength(URL url, int timeout);
114
* Please prefer getURLInfo when several infos are needed.
118
* @return last modified timestamp of the given url
120
public long getLastModified(URL url);
123
* Please prefer getURLInfo when several infos are needed.
127
* @return last modified timestamp of the given url
129
public long getLastModified(URL url, int timeout);
132
* Returns the URLInfo of the given url or a {@link #UNAVAILABLE} instance,
133
* if the url is not reachable.
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.
139
public URLInfo getURLInfo(URL url);
142
* never returns null, return UNAVAILABLE when url is not reachable
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.
149
public URLInfo getURLInfo(URL url, int timeout);
151
public InputStream openStream(URL url) throws IOException;
153
public void download(URL src, File dest, CopyProgressListener l) throws IOException;
155
public void upload(File src, URL dest, CopyProgressListener l) throws IOException;
157
public void setRequestMethod(int requestMethod);