rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java
changeset 1722 fd3a354d6e8f
parent 1720 3b960d9631b2
child 1730 795b040ac8f2
     1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Sun Nov 09 06:54:07 2014 +0100
     1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Sun Nov 09 10:36:08 2014 +0100
     1.3 @@ -235,11 +235,7 @@
     1.4                  while (resource.startsWith("/")) {
     1.5                      resource = resource.substring(1);
     1.6                  }
     1.7 -                InputStream emul = resources.get(resource);
     1.8 -                if (emul == null) {
     1.9 -                    throw new IOException("Can't find " + resource);
    1.10 -                }
    1.11 -                readResource(emul, this);
    1.12 +                requireResourceImpl(resource);
    1.13                  asBinary.remove(resource);
    1.14              }
    1.15              scripts = new StringArray();
    1.16 @@ -260,6 +256,14 @@
    1.17          }
    1.18      }
    1.19  
    1.20 +    final void requireResourceImpl(String resource) throws IOException {
    1.21 +        InputStream emul = resources.get(resource);
    1.22 +        if (emul == null) {
    1.23 +            throw new IOException("Can't find " + resource);
    1.24 +        }
    1.25 +        readResource(emul, this);
    1.26 +    }
    1.27 +
    1.28      private static void readResource(InputStream emul, Appendable out) throws IOException {
    1.29          try {
    1.30              int state = 0;
    1.31 @@ -703,6 +707,11 @@
    1.32              out.append("\n  return vm.").append(cls).append("(instance);");
    1.33              out.append("\n}");
    1.34          }
    1.35 +
    1.36 +        @Override
    1.37 +        protected void requireResource(String resourcePath) throws IOException {
    1.38 +            requireResourceImpl(resourcePath);
    1.39 +        }
    1.40      }
    1.41  
    1.42      private static final class Extension extends VM {
    1.43 @@ -795,5 +804,10 @@
    1.44              out.append(cls).append(" = f;})(instance);");
    1.45              out.append("\n}");
    1.46          }
    1.47 +
    1.48 +        @Override
    1.49 +        protected void requireResource(String resourcePath) throws IOException {
    1.50 +            requireResourceImpl(resourcePath);
    1.51 +        }
    1.52      }
    1.53  }