< prev index next >

src/jdk.zipfs/share/classes/jdk/nio/zipfs/JarFileSystem.java

Print this page
rev 48062 : 8192833: JEP 322: Time-Based Release Versioning


  53     private Function<byte[],byte[]> lookup;
  54 
  55     @Override
  56     IndexNode getInode(byte[] path) {
  57         // check for an alias to a versioned entry
  58         byte[] versionedPath = lookup.apply(path);
  59         return versionedPath == null ? super.getInode(path) : super.getInode(versionedPath);
  60     }
  61 
  62     JarFileSystem(ZipFileSystemProvider provider, Path zfpath, Map<String,?> env)
  63             throws IOException {
  64         super(provider, zfpath, env);
  65         lookup = path -> path;  // lookup needs to be set before isMultiReleaseJar is called
  66                                 // because it eventually calls getEntry
  67         if (isMultiReleaseJar()) {
  68             int version;
  69             Object o = env.get("multi-release");
  70             if (o instanceof String) {
  71                 String s = (String)o;
  72                 if (s.equals("runtime")) {
  73                     version = Runtime.version().major();
  74                 } else {
  75                     version = Integer.parseInt(s);
  76                 }
  77             } else if (o instanceof Integer) {
  78                 version = (Integer)o;
  79             } else if (o instanceof Version) {
  80                 version = ((Version)o).major();
  81             } else {
  82                 throw new IllegalArgumentException("env parameter must be String, Integer, "
  83                         + "or Version");
  84             }
  85             lookup = createVersionedLinks(version < 0 ? 0 : version);
  86             setReadOnly();
  87         }
  88     }
  89 
  90     private boolean isMultiReleaseJar() throws IOException {
  91         try (InputStream is = newInputStream(getBytes("/META-INF/MANIFEST.MF"))) {
  92             String multiRelease = new Manifest(is).getMainAttributes()
  93                     .getValue(Attributes.Name.MULTI_RELEASE);
  94             return "true".equalsIgnoreCase(multiRelease);
  95         } catch (NoSuchFileException x) {
  96             return false;
  97         }
  98     }
  99 
 100     /**




  53     private Function<byte[],byte[]> lookup;
  54 
  55     @Override
  56     IndexNode getInode(byte[] path) {
  57         // check for an alias to a versioned entry
  58         byte[] versionedPath = lookup.apply(path);
  59         return versionedPath == null ? super.getInode(path) : super.getInode(versionedPath);
  60     }
  61 
  62     JarFileSystem(ZipFileSystemProvider provider, Path zfpath, Map<String,?> env)
  63             throws IOException {
  64         super(provider, zfpath, env);
  65         lookup = path -> path;  // lookup needs to be set before isMultiReleaseJar is called
  66                                 // because it eventually calls getEntry
  67         if (isMultiReleaseJar()) {
  68             int version;
  69             Object o = env.get("multi-release");
  70             if (o instanceof String) {
  71                 String s = (String)o;
  72                 if (s.equals("runtime")) {
  73                     version = Runtime.version().feature();
  74                 } else {
  75                     version = Integer.parseInt(s);
  76                 }
  77             } else if (o instanceof Integer) {
  78                 version = (Integer)o;
  79             } else if (o instanceof Version) {
  80                 version = ((Version)o).feature();
  81             } else {
  82                 throw new IllegalArgumentException("env parameter must be String, Integer, "
  83                         + "or Version");
  84             }
  85             lookup = createVersionedLinks(version < 0 ? 0 : version);
  86             setReadOnly();
  87         }
  88     }
  89 
  90     private boolean isMultiReleaseJar() throws IOException {
  91         try (InputStream is = newInputStream(getBytes("/META-INF/MANIFEST.MF"))) {
  92             String multiRelease = new Manifest(is).getMainAttributes()
  93                     .getValue(Attributes.Name.MULTI_RELEASE);
  94             return "true".equalsIgnoreCase(multiRelease);
  95         } catch (NoSuchFileException x) {
  96             return false;
  97         }
  98     }
  99 
 100     /**


< prev index next >