JavaScript in a browser can be at most three times slower than HotSpot when computing five or ten thousands of prime numbers
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.launcher;
20 import java.io.ByteArrayInputStream;
21 import java.io.ByteArrayOutputStream;
22 import java.io.Closeable;
24 import java.io.Flushable;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.io.InterruptedIOException;
28 import java.io.OutputStream;
29 import java.io.Reader;
30 import java.io.UnsupportedEncodingException;
31 import java.io.Writer;
32 import java.net.JarURLConnection;
34 import java.net.URISyntaxException;
36 import java.net.URLConnection;
37 import java.util.ArrayList;
38 import java.util.Arrays;
39 import java.util.Enumeration;
40 import java.util.HashSet;
41 import java.util.LinkedHashSet;
42 import java.util.List;
44 import java.util.Properties;
46 import java.util.concurrent.BlockingQueue;
47 import java.util.concurrent.Callable;
48 import java.util.concurrent.CountDownLatch;
49 import java.util.concurrent.LinkedBlockingQueue;
50 import java.util.concurrent.TimeUnit;
51 import java.util.jar.Attributes;
52 import java.util.jar.Manifest;
53 import java.util.logging.ConsoleHandler;
54 import java.util.logging.Level;
55 import java.util.logging.Logger;
56 import org.apidesign.bck2brwsr.launcher.InvocationContext.Resource;
57 import org.glassfish.grizzly.PortRange;
58 import org.glassfish.grizzly.http.server.HttpHandler;
59 import org.glassfish.grizzly.http.server.HttpServer;
60 import org.glassfish.grizzly.http.server.NetworkListener;
61 import org.glassfish.grizzly.http.server.Request;
62 import org.glassfish.grizzly.http.server.Response;
63 import org.glassfish.grizzly.http.server.ServerConfiguration;
64 import org.glassfish.grizzly.http.server.StaticHttpHandler;
65 import org.glassfish.grizzly.http.util.Header;
66 import org.glassfish.grizzly.http.util.HttpStatus;
67 import org.glassfish.grizzly.websockets.WebSocket;
68 import org.glassfish.grizzly.websockets.WebSocketAddOn;
69 import org.glassfish.grizzly.websockets.WebSocketApplication;
70 import org.glassfish.grizzly.websockets.WebSocketEngine;
73 * Lightweight server to launch Bck2Brwsr applications and tests.
74 * Supports execution in native browser as well as Java's internal
77 abstract class BaseHTTPLauncher extends Launcher implements Flushable, Closeable, Callable<HttpServer> {
78 static final Logger LOG = Logger.getLogger(BaseHTTPLauncher.class.getName());
79 private static final InvocationContext END = new InvocationContext(null, null, null);
80 private final Set<ClassLoader> loaders = new LinkedHashSet<ClassLoader>();
81 private final BlockingQueue<InvocationContext> methods = new LinkedBlockingQueue<InvocationContext>();
83 private final Res resources = new Res();
84 private final String cmd;
85 private Object[] brwsr;
86 private HttpServer server;
87 private CountDownLatch wait;
88 private Thread flushing;
90 public BaseHTTPLauncher(String cmd) {
92 addClassLoader(BaseHTTPLauncher.class.getClassLoader());
97 InvocationContext runMethod(InvocationContext c) throws IOException {
98 loaders.add(c.clazz.getClassLoader());
102 } catch (InterruptedException ex) {
103 throw new IOException(ex);
108 public void setTimeout(long ms) {
112 public void addClassLoader(ClassLoader url) {
113 this.loaders.add(url);
116 ClassLoader[] loaders() {
117 return loaders.toArray(new ClassLoader[loaders.size()]);
120 public void showURL(String startpage) throws IOException {
121 if (!startpage.startsWith("/")) {
122 startpage = "/" + startpage;
124 HttpServer s = initServer(".", true, "");
125 int last = startpage.lastIndexOf('/');
126 String prefix = startpage.substring(0, last);
127 String simpleName = startpage.substring(last);
128 s.getServerConfiguration().addHttpHandler(new SubTree(resources, prefix), "/");
131 launchServerAndBrwsr(s, simpleName);
132 } catch (Exception ex) {
133 throw new IOException(ex);
137 void showDirectory(File dir, String startpage, boolean addClasses) throws IOException {
138 if (!startpage.startsWith("/")) {
139 startpage = "/" + startpage;
141 String prefix = null;
142 if (!new File(dir, "bck2brwsr.js").exists()) {
143 int last = startpage.lastIndexOf('/');
145 prefix = startpage.substring(0, last);
148 HttpServer s = initServer(dir.getPath(), addClasses, prefix);
150 launchServerAndBrwsr(s, startpage);
151 } catch (Exception ex) {
152 throw new IOException(ex);
157 public void initialize() throws IOException {
160 } catch (InterruptedException ex) {
161 final InterruptedIOException iio = new InterruptedIOException(ex.getMessage());
164 } catch (Exception ex) {
165 if (ex instanceof IOException) {
166 throw (IOException)ex;
168 if (ex instanceof RuntimeException) {
169 throw (RuntimeException)ex;
171 throw new IOException(ex);
175 private HttpServer initServer(String path, boolean addClasses, String vmPrefix) throws IOException {
176 HttpServer s = HttpServer.createSimpleServer(null, new PortRange(8080, 65535));
178 ThreadPoolConfig fewThreads = ThreadPoolConfig.defaultConfig().copy().
179 setPoolName("Fx/Bck2 Brwsr").
182 ThreadPoolConfig oneKernel = ThreadPoolConfig.defaultConfig().copy().
183 setPoolName("Kernel Fx/Bck2").
186 for (NetworkListener nl : s.getListeners()) {
187 nl.getTransport().setWorkerThreadPoolConfig(fewThreads);
188 nl.getTransport().setKernelThreadPoolConfig(oneKernel);
191 final ServerConfiguration conf = s.getServerConfiguration();
192 VMAndPages vm = new VMAndPages();
193 conf.addHttpHandler(vm, "/");
194 if (vmPrefix != null) {
195 vm.registerVM(vmPrefix + "/bck2brwsr.js");
201 conf.addHttpHandler(new Classes(resources), "/classes/");
203 final WebSocketAddOn addon = new WebSocketAddOn();
204 for (NetworkListener listener : s.getListeners()) {
205 listener.registerAddOn(addon);
207 Logger l = Logger.getLogger("org.glassfish.grizzly.http.server.HttpHandler");
208 l.setLevel(Level.FINE);
209 l.setUseParentHandlers(false);
210 ConsoleHandler ch = new ConsoleHandler();
211 ch.setLevel(Level.ALL);
216 private static int resourcesCount;
217 private void executeInBrowser() throws InterruptedException, URISyntaxException, IOException {
218 wait = new CountDownLatch(1);
219 server = initServer(".", true, "");
220 final ServerConfiguration conf = server.getServerConfiguration();
222 class DynamicResourceHandler extends HttpHandler {
223 private final InvocationContext ic;
224 DynamicResourceHandler delegate;
225 public DynamicResourceHandler(InvocationContext ic) {
227 for (Resource r : ic.resources) {
228 conf.addHttpHandler(this, r.httpPath);
232 public void close(DynamicResourceHandler del) {
233 conf.removeHttpHandler(this);
238 public void service(Request request, Response response) throws Exception {
239 if (delegate != null) {
240 delegate.service(request, response);
244 if ("/dynamic".equals(request.getRequestURI())) {
245 boolean webSocket = false;
246 String mimeType = request.getParameter("mimeType");
247 List<String> params = new ArrayList<String>();
248 for (int i = 0; ; i++) {
249 String p = request.getParameter("param" + i);
254 if ("protocol:ws".equals(p)) {
258 final String cnt = request.getParameter("content");
259 String mangle = cnt.replace("%20", " ").replace("%0A", "\n");
260 ByteArrayInputStream is = new ByteArrayInputStream(mangle.getBytes("UTF-8"));
262 final Resource res = new Resource(is, mimeType, "/dynamic/res" + ++resourcesCount, params.toArray(new String[params.size()]));
264 url = registerWebSocket(res);
266 url = registerResource(res);
268 response.setHeader(Header.CacheControl, "no-cache");
269 response.setHeader(Header.Pragma, "no-cache");
270 response.getWriter().write(url.toString());
271 response.getWriter().write("\n");
275 for (Resource r : ic.resources) {
276 if (r.httpPath.equals(request.getRequestURI())) {
277 LOG.log(Level.INFO, "Serving HttpResource for {0}", request.getRequestURI());
278 response.setContentType(r.httpType);
279 response.setHeader(Header.CacheControl, "no-cache");
280 response.setHeader(Header.Pragma, "no-cache");
281 r.httpContent.reset();
282 String[] params = null;
283 if (r.parameters.length != 0) {
284 params = new String[r.parameters.length];
285 for (int i = 0; i < r.parameters.length; i++) {
286 params[i] = request.getParameter(r.parameters[i]);
287 if (params[i] == null) {
288 if ("http.method".equals(r.parameters[i])) {
289 params[i] = request.getMethod().toString();
290 } else if ("http.requestBody".equals(r.parameters[i])) {
291 Reader rdr = request.getReader();
292 StringBuilder sb = new StringBuilder();
300 params[i] = sb.toString();
301 } else if (r.parameters[i].startsWith("http.header.")) {
302 params[i] = request.getHeader(r.parameters[i].substring(12));
305 if (params[i] == null) {
311 copyStream(r.httpContent, response.getOutputStream(), null, params);
316 private URI registerWebSocket(Resource r) {
317 WebSocketEngine.getEngine().register("", r.httpPath, new WS(r));
318 return pageURL("ws", server, r.httpPath);
321 private URI registerResource(Resource r) {
322 if (!ic.resources.contains(r)) {
324 conf.addHttpHandler(this, r.httpPath);
326 return pageURL("http", server, r.httpPath);
330 conf.addHttpHandler(new Page(resources, harnessResource()), "/execute");
332 conf.addHttpHandler(new HttpHandler() {
334 List<InvocationContext> cases = new ArrayList<InvocationContext>();
335 DynamicResourceHandler prev;
337 public void service(Request request, Response response) throws Exception {
338 String id = request.getParameter("request");
339 String value = request.getParameter("result");
340 String timeText = request.getParameter("time");
341 if (value != null && value.indexOf((char)0xC5) != -1) {
342 value = toUTF8(value);
345 if (timeText != null) {
347 time = (int) Double.parseDouble(timeText);
348 } catch (NumberFormatException numberFormatException) {
355 InvocationContext mi = null;
358 if (id != null && value != null) {
359 LOG.log(Level.INFO, "Received result for case {0} = {1}", new Object[]{id, value});
360 value = decodeURL(value);
361 int indx = Integer.parseInt(id);
362 cases.get(indx).result(value, time, null);
363 if (++indx < cases.size()) {
364 mi = cases.get(indx);
365 LOG.log(Level.INFO, "Re-executing case {0}", indx);
369 if (!cases.isEmpty()) {
370 LOG.info("Re-executing test cases");
381 response.getWriter().write("");
384 LOG.log(Level.INFO, "End of data reached. Exiting.");
387 final DynamicResourceHandler newRH = new DynamicResourceHandler(mi);
392 conf.addHttpHandler(prev, "/dynamic");
395 final String cn = mi.clazz.getName();
396 final String mn = mi.methodName;
397 LOG.log(Level.INFO, "Request for {0} case. Sending {1}.{2}", new Object[]{caseNmbr, cn, mn});
398 response.getWriter().write("{"
399 + "className: '" + cn + "', "
400 + "methodName: '" + mn + "', "
401 + "request: " + caseNmbr
403 if (mi.html != null) {
404 response.getWriter().write(", html: '");
405 response.getWriter().write(encodeJSON(mi.html));
406 response.getWriter().write("'");
408 response.getWriter().write("}");
412 this.brwsr = launchServerAndBrwsr(server, "/execute");
415 private static String encodeJSON(String in) {
416 StringBuilder sb = new StringBuilder();
417 for (int i = 0; i < in.length(); i++) {
418 char ch = in.charAt(i);
419 if (ch < 32 || ch == '\'' || ch == '"') {
421 String hs = "0000" + Integer.toHexString(ch);
422 hs = hs.substring(hs.length() - 4);
428 return sb.toString();
432 public void shutdown() throws IOException {
433 synchronized (this) {
434 if (flushing != null) {
435 flushing.interrupt();
441 int prev = methods.size();
443 if (wait != null && wait.await(timeOut, TimeUnit.MILLISECONDS)) {
446 } catch (InterruptedException ex) {
447 throw new IOException(ex);
449 if (prev == methods.size()) {
452 "Timeout and no test has been executed meanwhile (at {0}). Giving up.",
458 "Timeout, but tests got from {0} to {1}. Trying again.",
459 new Object[]{prev, methods.size()}
462 stopServerAndBrwsr(server, brwsr);
465 static void copyStream(InputStream is, OutputStream os, String baseURL, String... params) throws IOException {
471 if (ch == '$' && params.length > 0) {
472 int cnt = is.read() - '0';
473 if (baseURL != null && cnt == 'U' - '0') {
474 os.write(baseURL.getBytes("UTF-8"));
476 if (cnt >= 0 && cnt < params.length) {
477 os.write(params[cnt].getBytes("UTF-8"));
489 private Object[] launchServerAndBrwsr(HttpServer server, final String page) throws IOException, URISyntaxException, InterruptedException {
491 URI uri = pageURL("http", server, page);
492 return showBrwsr(uri);
494 private static String toUTF8(String value) throws UnsupportedEncodingException {
495 byte[] arr = new byte[value.length()];
496 for (int i = 0; i < arr.length; i++) {
497 arr[i] = (byte)value.charAt(i);
499 return new String(arr, "UTF-8");
502 private static String decodeURL(String s) {
504 int pos = s.indexOf('%');
508 int i = Integer.parseInt(s.substring(pos + 1, pos + 2), 16);
509 s = s.substring(0, pos) + (char)i + s.substring(pos + 2);
513 private void stopServerAndBrwsr(HttpServer server, Object[] brwsr) throws IOException {
517 Process process = (Process)brwsr[0];
520 InputStream stdout = process.getInputStream();
521 InputStream stderr = process.getErrorStream();
522 drain("StdOut", stdout);
523 drain("StdErr", stderr);
527 res = process.waitFor();
528 } catch (InterruptedException ex) {
529 throw new IOException(ex);
531 LOG.log(Level.INFO, "Exit code: {0}", res);
533 deleteTree((File)brwsr[1]);
536 private static void drain(String name, InputStream is) throws IOException {
537 int av = is.available();
539 StringBuilder sb = new StringBuilder();
540 sb.append("v== ").append(name).append(" ==v\n");
542 sb.append((char)is.read());
544 sb.append("\n^== ").append(name).append(" ==^");
545 LOG.log(Level.INFO, sb.toString());
549 private void deleteTree(File file) {
553 File[] arr = file.listFiles();
563 public HttpServer call() throws Exception {
568 public synchronized void flush() throws IOException {
569 flushing = Thread.currentThread();
570 while (flushing == Thread.currentThread()) {
573 } catch (InterruptedException ex) {
574 LOG.log(Level.FINE, null, ex);
580 public void close() throws IOException {
584 protected Object[] showBrwsr(URI uri) throws IOException {
585 LOG.log(Level.INFO, "Showing {0}", uri);
588 LOG.log(Level.INFO, "Trying Desktop.browse on {0} {2} by {1}", new Object[] {
589 System.getProperty("java.vm.name"),
590 System.getProperty("java.vm.vendor"),
591 System.getProperty("java.vm.version"),
593 java.awt.Desktop.getDesktop().browse(uri);
594 LOG.log(Level.INFO, "Desktop.browse successfully finished");
596 } catch (UnsupportedOperationException ex) {
597 LOG.log(Level.INFO, "Desktop.browse not supported: {0}", ex.getMessage());
598 LOG.log(Level.FINE, null, ex);
599 } catch (IOException ex) {
600 LOG.log(Level.INFO, "Desktop.browse failed: {0}", ex.getMessage());
601 LOG.log(Level.FINE, null, ex);
605 String cmdName = cmd == null ? "xdg-open" : cmd;
607 cmdName, uri.toString()
609 LOG.log(Level.INFO, "Launching {0}", Arrays.toString(cmdArr));
610 final Process process = Runtime.getRuntime().exec(cmdArr);
611 return new Object[] { process, null };
615 abstract void generateBck2BrwsrJS(StringBuilder sb, Res loader) throws IOException;
616 abstract String harnessResource();
617 Object compileJar(URL jar, URL precompiled) throws IOException {
620 String compileFromClassPath(URL f, Res loader) throws IOException {
624 private static URI pageURL(String protocol, HttpServer server, final String page) {
625 NetworkListener listener = server.getListeners().iterator().next();
626 int port = listener.getPort();
628 return new URI(protocol + "://localhost:" + port + page);
629 } catch (URISyntaxException ex) {
630 throw new IllegalStateException(ex);
635 private final Set<URL> ignore = new HashSet<URL>();
637 Object compileJar(URL jarURL) throws IOException {
638 List<String[]> libraries = new ArrayList<String[]>();
639 for (ClassLoader loader : loaders) {
640 Enumeration<URL> en = loader.getResources("META-INF/MANIFEST.MF");
641 while (en.hasMoreElements()) {
642 URL e = en.nextElement();
643 Manifest mf = new Manifest(e.openStream());
644 for (Map.Entry<String, Attributes> entrySet : mf.getEntries().entrySet()) {
645 String key = entrySet.getKey();
646 Attributes attr = entrySet.getValue();
648 final String a = attr.getValue("Bck2BrwsrArtifactId");
649 final String g = attr.getValue("Bck2BrwsrGroupId");
650 final String v = attr.getValue("Bck2BrwsrVersion");
651 final String d = attr.getValue("Bck2BrwsrDebug");
653 if (g != null && a != null && v != null && "true".equals(d)) {
654 libraries.add(new String[] {
661 URL precompiled = null;
662 for (ClassLoader loader : loaders) {
663 for (String[] lib : libraries) {
664 final String res = "META-INF/maven/" + lib[1] + "/" + lib[0] + "/pom.properties";
665 URL props = loader.getResource(res);
667 URLConnection c = props.openConnection();
668 Properties load = new Properties();
669 final InputStream is = c.getInputStream();
672 if (lib[2].equals(load.getProperty("version"))) {
673 if (c instanceof JarURLConnection) {
674 final URL definedInURL = ((JarURLConnection)c).getJarFileURL();
675 if (definedInURL.equals(jarURL)) {
676 precompiled = loader.getResource(lib[3]);
683 Object ret = BaseHTTPLauncher.this.compileJar(jarURL, precompiled);
687 String compileFromClassPath(URL f) throws IOException {
688 return BaseHTTPLauncher.this.compileFromClassPath(f, this);
690 public URL get(String resource, int skip) throws IOException {
691 if (!resource.endsWith(".class")) {
692 return getResource(resource, skip);
695 for (ClassLoader l : loaders) {
696 Enumeration<URL> en = l.getResources(resource);
697 while (en.hasMoreElements()) {
698 u = en.nextElement();
699 if (u.toExternalForm().matches("^.*emul.*rt\\.jar.*$")) {
705 if (u.toExternalForm().contains("rt.jar")) {
706 LOG.log(Level.WARNING, "No fallback to bootclasspath for {0}", u);
711 throw new IOException("Can't find " + resource);
713 private URL getResource(String resource, int skip) throws IOException {
714 for (ClassLoader l : loaders) {
715 Enumeration<URL> en = l.getResources(resource);
716 while (en.hasMoreElements()) {
717 final URL now = en.nextElement();
718 if (now.toExternalForm().contains("sisu-inject-bean")) {
719 // certainly we don't want this resource, as that
720 // module is not compiled with target 1.6, currently
723 if (now.getProtocol().equals("jar")) {
724 JarURLConnection juc = (JarURLConnection) now.openConnection();
725 if (now.getFile().endsWith(".class") && ignore.contains(juc.getJarFileURL())) {
734 throw new IOException("Not found (anymore of) " + resource);
738 private static class Page extends HttpHandler {
739 final String resource;
740 private final String[] args;
741 private final Res res;
743 public Page(Res res, String resource, String... args) {
745 this.resource = resource;
746 this.args = args.length == 0 ? new String[] { "$0" } : args;
750 public void service(Request request, Response response) throws Exception {
751 String r = computePage(request);
752 if (r.startsWith("/")) {
755 String[] replace = {};
756 if (r.endsWith(".html")) {
757 response.setContentType("text/html");
758 LOG.info("Content type text/html");
761 if (r.endsWith(".xhtml")) {
762 response.setContentType("application/xhtml+xml");
763 LOG.info("Content type application/xhtml+xml");
766 OutputStream os = response.getOutputStream();
768 InputStream is = res.get(r, 0).openStream();
769 copyStream(is, os, request.getRequestURL().toString(), replace);
770 } catch (IOException ex) {
771 response.setDetailMessage(ex.getLocalizedMessage());
773 response.setStatus(404);
777 protected String computePage(Request request) {
780 r = request.getHttpHandlerPath();
786 private static class SubTree extends Page {
788 public SubTree(Res res, String resource, String... args) {
789 super(res, resource, args);
793 protected String computePage(Request request) {
794 return resource + request.getHttpHandlerPath();
800 private class VMAndPages extends StaticHttpHandler {
801 private String vmResource;
803 public VMAndPages() {
804 super((String[]) null);
808 public void service(Request request, Response response) throws Exception {
809 if ("true".equals(request.getParameter("exit"))) {
810 LOG.info("Exit request received. Shutting down!");
813 if (request.getRequestURI().equals(vmResource)) {
814 response.setCharacterEncoding("UTF-8");
815 response.setContentType("text/javascript");
816 StringBuilder sb = new StringBuilder();
817 generateBck2BrwsrJS(sb, BaseHTTPLauncher.this.resources);
818 response.getWriter().write(sb.toString());
820 super.service(request, response);
824 private void registerVM(String vmResource) {
825 this.vmResource = vmResource;
829 private static class Classes extends HttpHandler {
830 private final Res loader;
832 public Classes(Res loader) {
833 this.loader = loader;
837 public void service(Request request, Response response) throws Exception {
838 String res = request.getHttpHandlerPath();
839 if (res.startsWith("/")) {
840 res = res.substring(1);
842 String skip = request.getParameter("skip");
843 int skipCnt = skip == null ? 0 : Integer.parseInt(skip);
844 URL url = loader.get(res, skipCnt);
845 if (url != null && !res.equals("META-INF/MANIFEST.MF")) try {
846 response.setCharacterEncoding("UTF-8");
847 if (url.getProtocol().equals("jar")) {
848 JarURLConnection juc = (JarURLConnection) url.openConnection();
851 s = loader.compileJar(juc.getJarFileURL());
852 } catch (IOException iOException) {
853 throw new IOException("Can't compile " + url.toExternalForm(), iOException);
855 if (s instanceof String) {
856 Writer w = response.getWriter();
861 if (s instanceof InputStream) {
862 copyStream((InputStream) s, response.getOutputStream(), null);
866 if (url.getProtocol().equals("file")) {
867 final String filePart = url.getFile();
868 if (filePart.endsWith(res)) {
873 filePart.substring(0, filePart.length() - res.length())
876 String s = loader.compileFromClassPath(url);
878 Writer w = response.getWriter();
884 } catch (IOException ex) {
885 LOG.log(Level.SEVERE, "Cannot handle " + res, ex);
887 InputStream is = null;
890 throw new IOException("Resource not found");
892 is = url.openStream();
893 response.setContentType("text/javascript");
894 Writer w = response.getWriter();
896 for (int i = 0;; i++) {
910 w.append(Integer.toString(b));
913 } catch (IOException ex) {
914 response.setStatus(HttpStatus.NOT_FOUND_404);
916 response.setDetailMessage(ex.getMessage());
925 private static class WS extends WebSocketApplication {
927 private final Resource r;
929 private WS(Resource r) {
934 public void onMessage(WebSocket socket, String text) {
936 r.httpContent.reset();
937 ByteArrayOutputStream out = new ByteArrayOutputStream();
938 copyStream(r.httpContent, out, null, text);
939 String s = new String(out.toByteArray(), "UTF-8");
941 } catch (IOException ex) {
942 LOG.log(Level.WARNING, null, ex);