Merging from default branch and resolving conflicts. mvn install -DskipTests passes OK.
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();
62 static long bytesToLong(byte b1, byte b2, int shift) {
63 return (((long)b1 << 56) +
64 ((long)b2 & 255) << 48) >> shift;
67 static String loadHello() throws IOException {
70 en = Resources.class.getClassLoader().getResources("META-INF/ahoj");
71 } catch (SecurityException ex) {
72 return "SecurityException";
74 StringBuilder sb = new StringBuilder();
75 while (en.hasMoreElements()) {
76 URL url = en.nextElement();
77 sb.append(readIS(url.openStream(), true));
79 return sb.toString().toString();
81 static String loadJustHello() throws IOException {
82 URL url = Resources.class.getResource("/META-INF/ahoj");
83 StringBuilder sb = new StringBuilder();
84 sb.append(readIS(url.openStream(), true));
85 return sb.toString().toString();