Can't close the JAR, we read its resources later closure
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 26 May 2014 18:21:36 +0200
branchclosure
changeset 1601a872960dce93
parent 1600 824cb8b9c4f9
child 1602 5591182757a0
Can't close the JAR, we read its resources later
rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java
     1.1 --- a/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java	Mon May 26 18:21:24 2014 +0200
     1.2 +++ b/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java	Mon May 26 18:21:36 2014 +0200
     1.3 @@ -63,28 +63,27 @@
     1.4       * @throws IOException if something goes wrong
     1.5       */
     1.6      public static Bck2Brwsr configureFrom(Bck2Brwsr c, File jar) throws IOException {
     1.7 -        try (JarFile jf = new JarFile(jar)) {
     1.8 -            List<String> classes = new ArrayList<>();
     1.9 -            List<String> resources = new ArrayList<>();
    1.10 -            Set<String> exported = new HashSet<>();
    1.11 -            
    1.12 -            listJAR(jf, classes, resources, exported);
    1.13 -            
    1.14 -            class JarRes extends EmulationResources implements Bck2Brwsr.Resources {
    1.15 +        final JarFile jf = new JarFile(jar);
    1.16 +        List<String> classes = new ArrayList<>();
    1.17 +        List<String> resources = new ArrayList<>();
    1.18 +        Set<String> exported = new HashSet<>();
    1.19  
    1.20 -                @Override
    1.21 -                public InputStream get(String resource) throws IOException {
    1.22 -                    InputStream is = jf.getInputStream(new ZipEntry(resource));
    1.23 -                    return is == null ? super.get(resource) : is;
    1.24 -                }
    1.25 +        listJAR(jf, classes, resources, exported);
    1.26 +
    1.27 +        class JarRes extends EmulationResources implements Bck2Brwsr.Resources {
    1.28 +
    1.29 +            @Override
    1.30 +            public InputStream get(String resource) throws IOException {
    1.31 +                InputStream is = jf.getInputStream(new ZipEntry(resource));
    1.32 +                return is == null ? super.get(resource) : is;
    1.33              }
    1.34 -            return Bck2Brwsr.newCompiler()
    1.35 -                .library(true)
    1.36 -                .addClasses(classes.toArray(new String[classes.size()]))
    1.37 -                .addExported(exported.toArray(new String[exported.size()]))
    1.38 -                .addResources(resources.toArray(new String[resources.size()]))
    1.39 -                .resources(new JarRes());
    1.40          }
    1.41 +        return Bck2Brwsr.newCompiler()
    1.42 +            .library(true)
    1.43 +            .addClasses(classes.toArray(new String[classes.size()]))
    1.44 +            .addExported(exported.toArray(new String[exported.size()]))
    1.45 +            .addResources(resources.toArray(new String[resources.size()]))
    1.46 +            .resources(new JarRes());
    1.47      }
    1.48      
    1.49      private static void listJAR(