619 } else { 620 // our best guess for the other cases 621 uc.setUseCaches(false); 622 InputStream is = uc.getInputStream(); 623 is.close(); 624 } 625 return url; 626 } catch (Exception e) { 627 return null; 628 } 629 } 630 631 Resource getResource(final String name, boolean check) { 632 final URL url; 633 try { 634 url = new URL(base, ParseUtil.encodePath(name, false)); 635 } catch (MalformedURLException e) { 636 throw new IllegalArgumentException("name"); 637 } 638 final URLConnection uc; 639 try { 640 if (check) { 641 URLClassPath.check(url); 642 } 643 uc = url.openConnection(); 644 InputStream in = uc.getInputStream(); 645 if (uc instanceof JarURLConnection) { 646 /* Need to remember the jar file so it can be closed 647 * in a hurry. 648 */ 649 JarURLConnection juc = (JarURLConnection)uc; 650 jarfile = JarLoader.checkJar(juc.getJarFile()); 651 } 652 } catch (Exception e) { 653 return null; 654 } 655 return new Resource() { 656 public String getName() { return name; } 657 public URL getURL() { return url; } 658 public URL getCodeSourceURL() { return base; } 659 public InputStream getInputStream() throws IOException { 660 return uc.getInputStream(); 661 } 662 public int getContentLength() throws IOException { 663 return uc.getContentLength(); 664 } 665 }; 666 } 667 668 /* 669 * Returns the Resource for the specified name, or null if not 670 * found or the caller does not have the permission to get the 671 * resource. 672 */ | 619 } else { 620 // our best guess for the other cases 621 uc.setUseCaches(false); 622 InputStream is = uc.getInputStream(); 623 is.close(); 624 } 625 return url; 626 } catch (Exception e) { 627 return null; 628 } 629 } 630 631 Resource getResource(final String name, boolean check) { 632 final URL url; 633 try { 634 url = new URL(base, ParseUtil.encodePath(name, false)); 635 } catch (MalformedURLException e) { 636 throw new IllegalArgumentException("name"); 637 } 638 final URLConnection uc; 639 URLConnection uce = null; 640 try { 641 if (check) { 642 URLClassPath.check(url); 643 } 644 uc = url.openConnection(); 645 uce = uc; 646 InputStream in = uc.getInputStream(); 647 if (uc instanceof JarURLConnection) { 648 /* Need to remember the jar file so it can be closed 649 * in a hurry. 650 */ 651 JarURLConnection juc = (JarURLConnection)uc; 652 jarfile = JarLoader.checkJar(juc.getJarFile()); 653 } 654 } catch (Exception e) { 655 if (null != uce && uce instanceof JarURLConnection) { 656 /* Need to create jarfile to be able to close fd; 657 * cannot use getJarFile() on resource URL. 658 */ 659 try { 660 String sbase = base.toString(); 661 int sep = sbase.indexOf("!/"); 662 URL urlf = new URL(sbase.substring(0, sep + 2)); 663 URLConnection ucf = urlf.openConnection(); 664 JarURLConnection jucf = (JarURLConnection)ucf; 665 jarfile = JarLoader.checkJar(jucf.getJarFile()); 666 } catch (Exception e1) { 667 // ignore 668 } 669 } 670 return null; 671 } 672 return new Resource() { 673 public String getName() { return name; } 674 public URL getURL() { return url; } 675 public URL getCodeSourceURL() { return base; } 676 public InputStream getInputStream() throws IOException { 677 return uc.getInputStream(); 678 } 679 public int getContentLength() throws IOException { 680 return uc.getContentLength(); 681 } 682 }; 683 } 684 685 /* 686 * Returns the Resource for the specified name, or null if not 687 * found or the caller does not have the permission to get the 688 * resource. 689 */ |