578 return manifests.get(fn); 579 } 580 581 // The map of loaded system packages 582 private static final ConcurrentHashMap<String, Package> pkgs 583 = new ConcurrentHashMap<>(); 584 585 // Maps each directory or zip file name to its corresponding manifest, if 586 // it exists 587 private static final ConcurrentHashMap<String, CachedManifest> manifests 588 = new ConcurrentHashMap<>(); 589 590 private static class CachedManifest { 591 private static final Manifest EMPTY_MANIFEST = new Manifest(); 592 private final String fileName; 593 private final URL url; 594 private volatile Manifest manifest; 595 596 CachedManifest(final String fileName) { 597 this.fileName = fileName; 598 this.url = AccessController.doPrivileged(new PrivilegedAction<URL>() { 599 public URL run() { 600 final File file = new File(fileName); 601 if (file.isFile()) { 602 try { 603 return ParseUtil.fileToEncodedURL(file); 604 } catch (MalformedURLException e) { 605 } 606 } 607 return null; 608 } 609 }); 610 } 611 612 public URL getURL() { 613 return url; 614 } 615 616 public Manifest getManifest() { 617 if (url == null) { 618 return EMPTY_MANIFEST; 619 } 620 Manifest m = manifest; 621 if (m != null) { 622 return m; 623 } 624 synchronized (this) { 625 m = manifest; 626 if (m != null) { 627 return m; 628 } 629 m = AccessController.doPrivileged(new PrivilegedAction<Manifest>() { 630 public Manifest run() { 631 try (FileInputStream fis = new FileInputStream(fileName); 632 JarInputStream jis = new JarInputStream(fis, false)) { 633 return jis.getManifest(); 634 } catch (IOException e) { 635 return null; 636 } 637 } 638 }); 639 manifest = m = (m == null ? EMPTY_MANIFEST : m); 640 } 641 return m; 642 } 643 } 644 645 private static native String getSystemPackage0(String name); 646 private static native String[] getSystemPackages0(); 647 648 /* 649 * Private storage for the package name and attributes. | 578 return manifests.get(fn); 579 } 580 581 // The map of loaded system packages 582 private static final ConcurrentHashMap<String, Package> pkgs 583 = new ConcurrentHashMap<>(); 584 585 // Maps each directory or zip file name to its corresponding manifest, if 586 // it exists 587 private static final ConcurrentHashMap<String, CachedManifest> manifests 588 = new ConcurrentHashMap<>(); 589 590 private static class CachedManifest { 591 private static final Manifest EMPTY_MANIFEST = new Manifest(); 592 private final String fileName; 593 private final URL url; 594 private volatile Manifest manifest; 595 596 CachedManifest(final String fileName) { 597 this.fileName = fileName; 598 this.url = AccessController.doPrivileged(new PrivilegedAction<>() { 599 public URL run() { 600 final File file = new File(fileName); 601 if (file.isFile()) { 602 try { 603 return ParseUtil.fileToEncodedURL(file); 604 } catch (MalformedURLException e) { 605 } 606 } 607 return null; 608 } 609 }); 610 } 611 612 public URL getURL() { 613 return url; 614 } 615 616 public Manifest getManifest() { 617 if (url == null) { 618 return EMPTY_MANIFEST; 619 } 620 Manifest m = manifest; 621 if (m != null) { 622 return m; 623 } 624 synchronized (this) { 625 m = manifest; 626 if (m != null) { 627 return m; 628 } 629 m = AccessController.doPrivileged(new PrivilegedAction<>() { 630 public Manifest run() { 631 try (FileInputStream fis = new FileInputStream(fileName); 632 JarInputStream jis = new JarInputStream(fis, false)) { 633 return jis.getManifest(); 634 } catch (IOException e) { 635 return null; 636 } 637 } 638 }); 639 manifest = m = (m == null ? EMPTY_MANIFEST : m); 640 } 641 return m; 642 } 643 } 644 645 private static native String getSystemPackage0(String name); 646 private static native String[] getSystemPackages0(); 647 648 /* 649 * Private storage for the package name and attributes. |