Testing loading of resource from an extension and preparing for loading them from multiple extensions
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 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.vm4brwsr;
20 import java.io.IOException;
21 import java.io.InputStream;
23 import java.util.Enumeration;
27 * @author Jaroslav Tulach <jtulach@netbeans.org>
29 public class Resources {
30 public static String loadKO() throws IOException {
31 InputStream is = Resources.class.getResourceAsStream("ko.js");
32 return readIS(is, false);
35 static String loadClazz() throws IOException {
36 InputStream is = Resources.class.getResourceAsStream("Bck2BrwsrToolkit.class");
37 return readIS(is, false);
40 private static String readIS(InputStream is, boolean asString) throws IOException {
42 return "No resource found!";
44 byte[] arr = new byte[4092];
45 int len = is.read(arr);
47 return "No data read! Len: " + len;
51 return new String(arr, 0, len, "UTF-8").toString().toString();
54 StringBuilder sb = new StringBuilder();
56 for (int i = 0; i < len; i++) {
57 sb.append(arr[i]).append(", ");
60 return sb.toString().toString();
63 static String loadHello() throws IOException {
66 en = Resources.class.getClassLoader().getResources("META-INF/ahoj");
67 } catch (SecurityException ex) {
68 return "SecurityException";
70 StringBuilder sb = new StringBuilder();
71 while (en.hasMoreElements()) {
72 URL url = en.nextElement();
73 sb.append(readIS(url.openStream(), true));
75 return sb.toString().toString();
77 static String loadJustHello() throws IOException {
78 URL url = Resources.class.getResource("/META-INF/ahoj");
79 StringBuilder sb = new StringBuilder();
80 sb.append(readIS(url.openStream(), true));
81 return sb.toString().toString();