/** * Returns a connection to the jar file pointed by this <code>URL</code> * in the file system * * @return java.net.URLConnection A connection to the resource pointed by * this url. * @param u * java.net.URL The URL to which the connection is pointing to * * @throws IOException * thrown if an IO error occurs when this method tries to * establish connection. */ @Override protected URLConnection openConnection(URL u) throws IOException { return new JarURLConnectionImpl(u); }
String entryName = getEntryName(); cType = guessContentTypeFromName(entryName); } else { try { connect(); cType = jarFileURLConnection.getContentType(); } catch (IOException ioe) {
/** * @see java.net.URLConnection#connect() */ @Override public void connect() throws IOException { if (!connected) { findJarFile(); // ensure the file can be found findJarEntry(); // ensure the entry, if any, can be found connected = true; } }
/** * Returns the content length of the resource. Test cases reveal that if the * URL is referring to a Jar file, this method answers a content-length * returned by URLConnection. For jar entry it should return it's size. * Otherwise, it will return -1. * * @return the content length */ @Override public int getContentLength() { try { connect(); if (jarEntry == null) { return jarFileURLConnection.getContentLength(); } return (int) getJarEntry().getSize(); } catch (IOException e) { // Ignored } return -1; }
/** * Returns the Jar file referred by this {@code URLConnection}. * * @throws IOException * thrown if an IO error occurs while connecting to the * resource. */ @Override public JarFile getJarFile() throws IOException { connect(); return jarFile; }
/** * Returns the Jar file referred by this {@code URLConnection} * * @throws IOException * if an IO error occurs while connecting to the resource. */ private void findJarFile() throws IOException { if (getUseCaches()) { synchronized (jarCache) { jarFile = jarCache.get(jarFileURL); } if (jarFile == null) { JarFile jar = openJarFile(); synchronized (jarCache) { jarFile = jarCache.get(jarFileURL); if (jarFile == null) { jarCache.put(jarFileURL, jar); jarFile = jar; } else { jar.close(); } } } } else { jarFile = openJarFile(); } if (jarFile == null) { throw new IOException(); } }
@Override public void close() throws IOException { super.close(); if (!getUseCaches()) { closed = true; jarFile.close(); } } }
/** * @param url * the URL of the JAR * @throws MalformedURLException * if the URL is malformed * @throws IOException * if there is a problem opening the connection. */ public JarURLConnectionImpl(URL url) throws MalformedURLException, IOException { super(url); jarFileURL = getJarFileURL(); jarFileURLConnection = jarFileURL.openConnection(); }
/** * Look up the JarEntry of the entry referenced by this {@code * URLConnection}. */ private void findJarEntry() throws IOException { if (getEntryName() == null) { return; } jarEntry = jarFile.getJarEntry(getEntryName()); if (jarEntry == null) { throw new FileNotFoundException(getEntryName()); } }
/** * Returns the JarEntry of the entry referenced by this {@code * URLConnection}. * * @return the JarEntry referenced * * @throws IOException * if an IO error occurs while getting the entry */ @Override public JarEntry getJarEntry() throws IOException { connect(); return jarEntry; }
/** * Returns the content length of the resource. Test cases reveal that if the * URL is referring to a Jar file, this method answers a content-length * returned by URLConnection. For jar entry it should return it's size. * Otherwise, it will return -1. * * @return the content length */ @Override public int getContentLength() { try { connect(); if (jarEntry == null) { return jarFileURLConnection.getContentLength(); } return (int) getJarEntry().getSize(); } catch (IOException e) { // Ignored } return -1; }
/** * Returns the Jar file referred by this {@code URLConnection} * * @throws IOException * if an IO error occurs while connecting to the resource. */ private void findJarFile() throws IOException { if (getUseCaches()) { synchronized (jarCache) { jarFile = jarCache.get(jarFileURL); } if (jarFile == null) { JarFile jar = openJarFile(); synchronized (jarCache) { jarFile = jarCache.get(jarFileURL); if (jarFile == null) { jarCache.put(jarFileURL, jar); jarFile = jar; } else { jar.close(); } } } } else { jarFile = openJarFile(); } if (jarFile == null) { throw new IOException(); } }
@Override public void close() throws IOException { super.close(); if (!getUseCaches()) { closed = true; jarFile.close(); } } }
/** * @param url * the URL of the JAR * @throws MalformedURLException * if the URL is malformed * @throws IOException * if there is a problem opening the connection. */ public JarURLConnectionImpl(URL url) throws MalformedURLException, IOException { super(url); jarFileURL = getJarFileURL(); jarFileURLConnection = jarFileURL.openConnection(); }
/** * Look up the JarEntry of the entry referenced by this {@code * URLConnection}. */ private void findJarEntry() throws IOException { if (getEntryName() == null) { return; } jarEntry = jarFile.getJarEntry(getEntryName()); if (jarEntry == null) { throw new FileNotFoundException(getEntryName()); } }
String entryName = getEntryName(); cType = guessContentTypeFromName(entryName); } else { try { connect(); cType = jarFileURLConnection.getContentType(); } catch (IOException ioe) {
/** * @see java.net.URLConnection#connect() */ @Override public void connect() throws IOException { if (!connected) { findJarFile(); // ensure the file can be found findJarEntry(); // ensure the entry, if any, can be found connected = true; } }
/** * Creates an input stream for reading from this URL Connection. * * @return the input stream * * @throws IOException * if an IO error occurs while connecting to the resource. */ @Override public InputStream getInputStream() throws IOException { if (closed) { throw new IllegalStateException("JarURLConnection InputStream has been closed"); } connect(); if (jarInput != null) { return jarInput; } if (jarEntry == null) { throw new IOException("Jar entry not specified"); } return jarInput = new JarURLConnectionInputStream(jarFile .getInputStream(jarEntry), jarFile); }
/** * Returns the content length of the resource. Test cases reveal that if the * URL is referring to a Jar file, this method answers a content-length * returned by URLConnection. For jar entry it should return it's size. * Otherwise, it will return -1. * * @return the content length */ @Override public int getContentLength() { try { connect(); if (jarEntry == null) { return jarFileURLConnection.getContentLength(); } return (int) getJarEntry().getSize(); } catch (IOException e) { // Ignored } return -1; }
/** * Returns the Jar file referred by this {@code URLConnection} * * @throws IOException * if an IO error occurs while connecting to the resource. */ private void findJarFile() throws IOException { if (getUseCaches()) { synchronized (jarCache) { jarFile = jarCache.get(jarFileURL); } if (jarFile == null) { JarFile jar = openJarFile(); synchronized (jarCache) { jarFile = jarCache.get(jarFileURL); if (jarFile == null) { jarCache.put(jarFileURL, jar); jarFile = jar; } else { jar.close(); } } } } else { jarFile = openJarFile(); } if (jarFile == null) { throw new IOException(); } }