launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java
branchclosure
changeset 1513 ba912ef24b27
parent 1489 8d0fc428ff72
parent 1375 a6c71e376889
child 1528 984f8ed9e514
     1.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java	Sat Apr 26 19:13:56 2014 +0200
     1.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java	Wed Apr 30 15:04:10 2014 +0200
     1.3 @@ -221,14 +221,22 @@
     1.4       * @return the array of bytes in the given resource
     1.5       * @throws IOException I/O in case something goes wrong
     1.6       */
     1.7 -    public static byte[] read(String name) throws IOException {
     1.8 +    public static byte[] read(String name, int skip) throws IOException {
     1.9          URL u = null;
    1.10 -        Enumeration<URL> en = Console.class.getClassLoader().getResources(name);
    1.11 -        while (en.hasMoreElements()) {
    1.12 -            u = en.nextElement();
    1.13 +        if (!name.endsWith(".class")) {
    1.14 +            u = getResource(name, skip);
    1.15 +        } else {
    1.16 +            Enumeration<URL> en = Console.class.getClassLoader().getResources(name);
    1.17 +            while (en.hasMoreElements()) {
    1.18 +                u = en.nextElement();
    1.19 +            }
    1.20          }
    1.21          if (u == null) {
    1.22 -            throw new IOException("Can't find " + name);
    1.23 +            if (name.endsWith(".class")) {
    1.24 +                throw new IOException("Can't find " + name);
    1.25 +            } else {
    1.26 +                return null;
    1.27 +            }
    1.28          }
    1.29          try (InputStream is = u.openStream()) {
    1.30              byte[] arr;
    1.31 @@ -245,6 +253,19 @@
    1.32          }
    1.33      }
    1.34     
    1.35 +    private static URL getResource(String resource, int skip) throws IOException {
    1.36 +        URL u = null;
    1.37 +        Enumeration<URL> en = Console.class.getClassLoader().getResources(resource);
    1.38 +        while (en.hasMoreElements()) {
    1.39 +            final URL now = en.nextElement();
    1.40 +            if (--skip < 0) {
    1.41 +                u = now;
    1.42 +                break;
    1.43 +            }
    1.44 +        }
    1.45 +        return u;
    1.46 +    }
    1.47 +    
    1.48      @JavaScriptBody(args = {}, body = "vm.desiredAssertionStatus = true;")
    1.49      private static void turnAssetionStatusOn() {
    1.50      }