1 22 package org.jboss.virtual.plugins.context; 23 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.net.MalformedURLException ; 27 import java.net.URI ; 28 import java.net.URISyntaxException ; 29 import java.net.URL ; 30 import java.net.URLConnection ; 31 32 import org.jboss.virtual.VFSUtils; 33 import org.jboss.virtual.spi.VFSContext; 34 import org.jboss.virtual.spi.VirtualFileHandler; 35 36 42 public abstract class AbstractURLHandler extends AbstractVirtualFileHandler 43 { 44 45 private static final long serialVersionUID = 1L; 46 47 48 private final URL url; 49 50 59 public AbstractURLHandler(VFSContext context, VirtualFileHandler parent, URL url, String name) 60 { 61 super(context, parent, name); 62 if (url == null) 63 throw new IllegalArgumentException ("Null url"); 64 this.url = url; 65 } 66 67 72 public URL getURL() 73 { 74 return url; 75 } 76 77 public URL toURL() throws MalformedURLException , URISyntaxException 78 { 79 return getURL(); 80 } 81 82 public long getLastModified() throws IOException 83 { 84 checkClosed(); 85 URLConnection c = url.openConnection(); 86 return c.getLastModified(); 87 } 88 89 public long getSize() throws IOException 90 { 91 checkClosed(); 92 URLConnection c = url.openConnection(); 93 return c.getContentLength(); 94 } 95 96 public boolean isHidden() throws IOException 97 { 98 checkClosed(); 99 return false; 100 } 101 102 public InputStream openStream() throws IOException 103 { 104 checkClosed(); 105 return url.openStream(); 106 } 107 108 public URI toURI() throws URISyntaxException 109 { 110 return VFSUtils.toURI(url); 111 } 112 } 113 | Popular Tags |