1 /* |
1 /* |
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
32 import java.nio.file.Files; |
32 import java.nio.file.Files; |
33 import java.nio.file.Path; |
33 import java.nio.file.Path; |
34 import java.nio.file.SimpleFileVisitor; |
34 import java.nio.file.SimpleFileVisitor; |
35 import java.nio.file.attribute.BasicFileAttributes; |
35 import java.nio.file.attribute.BasicFileAttributes; |
36 import java.util.*; |
36 import java.util.*; |
|
37 import java.util.jar.Attributes; |
37 import java.util.jar.JarEntry; |
38 import java.util.jar.JarEntry; |
38 import java.util.jar.JarFile; |
39 import java.util.jar.JarFile; |
|
40 import java.util.jar.Manifest; |
39 |
41 |
40 /** |
42 /** |
41 * ClassFileReader reads ClassFile(s) of a given path that can be |
43 * ClassFileReader reads ClassFile(s) of a given path that can be |
42 * a .class file, a directory, or a JAR file. |
44 * a .class file, a directory, or a JAR file. |
43 */ |
45 */ |
152 public void remove() { |
154 public void remove() { |
153 throw new UnsupportedOperationException("Not supported yet."); |
155 throw new UnsupportedOperationException("Not supported yet."); |
154 } |
156 } |
155 } |
157 } |
156 |
158 |
|
159 public boolean isMultiReleaseJar() throws IOException { return false; } |
|
160 |
157 public String toString() { |
161 public String toString() { |
158 return path.toString(); |
162 return path.toString(); |
159 } |
163 } |
160 |
164 |
161 private static class DirectoryReader extends ClassFileReader { |
165 private static class DirectoryReader extends ClassFileReader { |
288 public Iterator<ClassFile> iterator() { |
292 public Iterator<ClassFile> iterator() { |
289 return iter; |
293 return iter; |
290 } |
294 } |
291 }; |
295 }; |
292 } |
296 } |
|
297 |
|
298 @Override |
|
299 public boolean isMultiReleaseJar() throws IOException { |
|
300 Manifest mf = this.jarfile.getManifest(); |
|
301 if (mf != null) { |
|
302 Attributes atts = mf.getMainAttributes(); |
|
303 return "true".equalsIgnoreCase(atts.getValue("Multi-Release")); |
|
304 } |
|
305 return false; |
|
306 } |
293 } |
307 } |
294 |
308 |
295 class JarFileIterator implements Iterator<ClassFile> { |
309 class JarFileIterator implements Iterator<ClassFile> { |
296 protected final JarFileReader reader; |
310 protected final JarFileReader reader; |
297 protected Enumeration<JarEntry> entries; |
311 protected Enumeration<JarEntry> entries; |