1 6 package fr.jayasoft.ivy.url; 7 8 import java.io.File ; 9 import java.io.IOException ; 10 import java.io.InputStream ; 11 import java.net.URL ; 12 import java.util.HashMap ; 13 import java.util.Map ; 14 15 import fr.jayasoft.ivy.util.CopyProgressListener; 16 17 23 public class URLHandlerDispatcher implements URLHandler { 24 protected Map _handlers = new HashMap (); 25 protected URLHandler _default = new BasicURLHandler(); 26 27 public URLHandlerDispatcher() { 28 } 29 30 public boolean isReachable(URL url) { 31 return getHandler(url.getProtocol()).isReachable(url); 32 } 33 34 public boolean isReachable(URL url, int timeout) { 35 return getHandler(url.getProtocol()).isReachable(url, timeout); 36 } 37 38 public long getContentLength(URL url) { 39 return getHandler(url.getProtocol()).getContentLength(url); 40 } 41 42 public long getContentLength(URL url, int timeout) { 43 return getHandler(url.getProtocol()).getContentLength(url, timeout); 44 } 45 46 47 public long getLastModified(URL url) { 48 return getHandler(url.getProtocol()).getLastModified(url); 49 } 50 51 public long getLastModified(URL url, int timeout) { 52 return getHandler(url.getProtocol()).getLastModified(url, timeout); 53 } 54 55 public URLInfo getURLInfo(URL url) { 56 return getHandler(url.getProtocol()).getURLInfo(url); 57 } 58 59 public URLInfo getURLInfo(URL url, int timeout) { 60 return getHandler(url.getProtocol()).getURLInfo(url, timeout); 61 } 62 public InputStream openStream(URL url) throws IOException { 63 return getHandler(url.getProtocol()).openStream(url); 64 } 65 66 public void download(URL src, File dest, CopyProgressListener l) throws IOException { 67 getHandler(src.getProtocol()).download(src, dest, l); 68 } 69 70 public void setDownloader(String protocol, URLHandler downloader) { 71 _handlers.put(protocol, downloader); 72 } 73 74 public URLHandler getHandler(String protocol) { 75 URLHandler downloader = (URLHandler)_handlers.get(protocol); 76 return downloader == null ? _default : downloader; 77 } 78 79 public URLHandler getDefault() { 80 return _default; 81 } 82 public void setDefault(URLHandler default1) { 83 _default = default1; 84 } 85 } 86 | Popular Tags |