1 11 12 package org.eclipse.osgi.framework.adaptor.core; 13 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.net.*; 17 18 21 22 public class BundleURLConnection extends URLConnection { 23 24 protected final BundleEntry bundleEntry; 25 26 27 protected InputStream in; 28 29 30 protected String contentType; 31 32 38 public BundleURLConnection(URL url, BundleEntry bundleEntry) { 39 super(url); 40 41 this.bundleEntry = bundleEntry; 42 this.in = null; 43 this.contentType = null; 44 } 45 46 public synchronized void connect() throws IOException { 47 if (!connected) { 48 if (bundleEntry != null) { 49 in = bundleEntry.getInputStream(); 50 connected = true; 51 } else { 52 throw new IOException (AdaptorMsg.formatter.getString("RESOURCE_NOT_FOUND_EXCEPTION", url)); } 54 } 55 } 56 57 public int getContentLength() { 58 return ((int) bundleEntry.getSize()); 59 } 60 61 public String getContentType() { 62 if (contentType == null) { 63 contentType = guessContentTypeFromName(bundleEntry.getName()); 64 65 if (contentType == null) { 66 if (!connected) { 67 try { 68 connect(); 69 } catch (IOException e) { 70 return (null); 71 } 72 } 73 try { 74 if (in.markSupported()) 75 contentType = guessContentTypeFromStream(in); 76 } catch (IOException e) { 77 } 78 } 79 } 80 81 return (contentType); 82 } 83 84 public boolean getDoInput() { 85 return (true); 86 } 87 88 public boolean getDoOutput() { 89 return (false); 90 } 91 92 public InputStream getInputStream() throws IOException { 93 if (!connected) { 94 connect(); 95 } 96 97 return (in); 98 } 99 100 public long getLastModified() { 101 long lastModified = bundleEntry.getTime(); 102 103 if (lastModified == -1) { 104 return (0); 105 } 106 107 return (lastModified); 108 } 109 110 114 public URL getLocalURL() { 115 return bundleEntry.getLocalURL(); 116 } 117 118 123 public URL getFileURL() { 124 return bundleEntry.getFileURL(); 125 } 126 } | Popular Tags |