1 16 package org.apache.commons.vfs.provider.jar; 17 18 import org.apache.commons.vfs.FileContent; 19 import org.apache.commons.vfs.FileSystemException; 20 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.io.OutputStream ; 24 import java.net.JarURLConnection ; 25 import java.net.MalformedURLException ; 26 import java.net.URL ; 27 import java.security.cert.Certificate ; 28 import java.util.jar.Attributes ; 29 import java.util.jar.JarEntry ; 30 import java.util.jar.JarFile ; 31 import java.util.jar.Manifest ; 32 33 38 public class JarURLConnectionImpl 39 extends JarURLConnection 40 { 41 private static final String HACK_URL = "jar:http://somehost/somejar.jar!/"; 43 44 private FileContent content; 45 private URL parentURL; 46 private JarFileObject file; 47 private String entryName; 48 49 public JarURLConnectionImpl(JarFileObject file, FileContent content) 50 throws MalformedURLException , FileSystemException 51 { 52 super(new URL (HACK_URL)); 54 55 this.url = file.getURL(); 56 this.content = content; 57 this.parentURL = file.getURL(); 58 this.entryName = file.getName().getPath(); 59 this.file = file; 60 } 61 62 63 public URL getJarFileURL() 64 { 65 return parentURL; 66 } 67 68 69 public String getEntryName() 70 { 71 return entryName; 72 } 73 74 75 public JarFile getJarFile() throws IOException 76 { 77 throw new FileSystemException("vfs.provider.jar/jar-file-no-access.error"); 78 } 79 80 81 public Manifest getManifest() throws IOException 82 { 83 return file.getManifest(); 84 } 85 86 87 public JarEntry getJarEntry() throws IOException 88 { 89 throw new FileSystemException("vfs.provider.jar/jar-entry-no-access.error"); 90 } 91 92 93 public Attributes getAttributes() throws IOException 94 { 95 return file.getAttributes(); 96 } 97 98 99 public Certificate [] getCertificates() 100 { 101 return file.doGetCertificates(); 102 } 103 104 105 public void connect() 106 { 107 connected = true; 108 } 109 110 public InputStream getInputStream() 111 throws IOException 112 { 113 return content.getInputStream(); 114 } 115 116 public OutputStream getOutputStream() 117 throws IOException 118 { 119 return content.getOutputStream(); 120 } 121 122 public int getContentLength() 123 { 124 try 125 { 126 return (int) content.getSize(); 127 } 128 catch (FileSystemException fse) 129 { 130 } 131 132 return -1; 133 } 134 135 } 136 | Popular Tags |