javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/Compile.java
branchclosure
changeset 1518 8261c59be151
parent 1505 706b66d8c481
child 1787 ea12a3bb4b33
     1.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/Compile.java	Tue Apr 29 14:59:40 2014 +0200
     1.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/Compile.java	Fri May 02 09:06:57 2014 +0200
     1.3 @@ -91,23 +91,8 @@
     1.4  
     1.5          final Map<String, ByteArrayOutputStream> class2BAOS = new HashMap<>();
     1.6  
     1.7 -        JavaFileObject file = new SimpleJavaFileObject(URI.create("mem://mem"), Kind.SOURCE) {
     1.8 -            @Override
     1.9 -            public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
    1.10 -                return code;
    1.11 -            }
    1.12 -        };
    1.13 -        final JavaFileObject htmlFile = new SimpleJavaFileObject(URI.create("mem://mem2"), Kind.OTHER) {
    1.14 -            @Override
    1.15 -            public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
    1.16 -                return html;
    1.17 -            }
    1.18 -
    1.19 -            @Override
    1.20 -            public InputStream openInputStream() throws IOException {
    1.21 -                return new ByteArrayInputStream(html.getBytes());
    1.22 -            }
    1.23 -        };
    1.24 +        JavaFileObject file = new Mem(URI.create("mem://mem"), Kind.SOURCE, code);
    1.25 +        final JavaFileObject htmlFile = new Mem2(URI.create("mem://mem2"), Kind.OTHER, html);
    1.26          
    1.27          final URI scratch;
    1.28          try {
    1.29 @@ -178,28 +163,11 @@
    1.30                  final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    1.31                  
    1.32                  class2BAOS.put(className.replace('.', '/') + ".class", buffer);
    1.33 -                return new SimpleJavaFileObject(sibling.toUri(), kind) {
    1.34 -                    @Override
    1.35 -                    public OutputStream openOutputStream() throws IOException {
    1.36 -                        return buffer;
    1.37 -                    }
    1.38 -                };
    1.39 +                return new Sibling(sibling.toUri(), kind, buffer);
    1.40              }
    1.41              
    1.42              if (kind == Kind.SOURCE) {
    1.43 -                return new SimpleJavaFileObject(scratch/*sibling.toUri()*/, kind) {
    1.44 -                    private final ByteArrayOutputStream data = new ByteArrayOutputStream();
    1.45 -                    @Override
    1.46 -                    public OutputStream openOutputStream() throws IOException {
    1.47 -                        return data;
    1.48 -                    }
    1.49 -                    
    1.50 -                    @Override
    1.51 -                    public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
    1.52 -                        data.close();
    1.53 -                        return new String(data.toByteArray());
    1.54 -                    }
    1.55 -                };
    1.56 +                return new Source(scratch/*sibling.toUri()*/, kind);
    1.57              }
    1.58              
    1.59              throw new IllegalStateException();
    1.60 @@ -215,5 +183,76 @@
    1.61                  
    1.62                  return null;
    1.63              }
    1.64 +
    1.65 +      @ExtraJavaScript(processByteCode = false, resource = "")
    1.66 +      private class Sibling extends SimpleJavaFileObject {
    1.67 +            private final ByteArrayOutputStream buffer;
    1.68 +
    1.69 +            public Sibling(URI uri, Kind kind, ByteArrayOutputStream buffer) {
    1.70 +                super(uri, kind);
    1.71 +                this.buffer = buffer;
    1.72 +            }
    1.73 +
    1.74 +            @Override
    1.75 +            public OutputStream openOutputStream() throws IOException {
    1.76 +                return buffer;
    1.77 +            }
    1.78 +        }
    1.79 +
    1.80 +      @ExtraJavaScript(processByteCode = false, resource = "")
    1.81 +      private class Source extends SimpleJavaFileObject {
    1.82 +            public Source(URI uri, Kind kind) {
    1.83 +                super(uri, kind);
    1.84 +            }
    1.85 +            private final ByteArrayOutputStream data = new ByteArrayOutputStream();
    1.86 +
    1.87 +            @Override
    1.88 +            public OutputStream openOutputStream() throws IOException {
    1.89 +                return data;
    1.90 +            }
    1.91 +
    1.92 +            @Override
    1.93 +            public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
    1.94 +                data.close();
    1.95 +                return new String(data.toByteArray());
    1.96 +            }
    1.97 +        }
    1.98 +    }
    1.99 +
   1.100 +    @ExtraJavaScript(processByteCode = false, resource = "")
   1.101 +    private static class Mem extends SimpleJavaFileObject {
   1.102 +
   1.103 +        private final String code;
   1.104 +
   1.105 +        public Mem(URI uri, Kind kind, String code) {
   1.106 +            super(uri, kind);
   1.107 +            this.code = code;
   1.108 +        }
   1.109 +
   1.110 +        @Override
   1.111 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
   1.112 +            return code;
   1.113 +        }
   1.114 +    }
   1.115 +
   1.116 +    @ExtraJavaScript(processByteCode = false, resource = "")
   1.117 +    private static class Mem2 extends SimpleJavaFileObject {
   1.118 +
   1.119 +        private final String html;
   1.120 +
   1.121 +        public Mem2(URI uri, Kind kind, String html) {
   1.122 +            super(uri, kind);
   1.123 +            this.html = html;
   1.124 +        }
   1.125 +
   1.126 +        @Override
   1.127 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
   1.128 +            return html;
   1.129 +        }
   1.130 +
   1.131 +        @Override
   1.132 +        public InputStream openInputStream() throws IOException {
   1.133 +            return new ByteArrayInputStream(html.getBytes());
   1.134 +        }
   1.135      }
   1.136  }