jaroslav@114: /** jaroslav@114: * Back 2 Browser Bytecode Translator jaroslav@114: * Copyright (C) 2012 Jaroslav Tulach jaroslav@114: * jaroslav@114: * This program is free software: you can redistribute it and/or modify jaroslav@114: * it under the terms of the GNU General Public License as published by jaroslav@114: * the Free Software Foundation, version 2 of the License. jaroslav@114: * jaroslav@114: * This program is distributed in the hope that it will be useful, jaroslav@114: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@114: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@114: * GNU General Public License for more details. jaroslav@114: * jaroslav@114: * You should have received a copy of the GNU General Public License jaroslav@114: * along with this program. Look for COPYING file in the top folder. jaroslav@114: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@114: */ jaroslav@114: package org.apidesign.vm4brwsr; jaroslav@114: jaroslav@181: import java.io.IOException; jaroslav@1493: import java.io.InputStream; jaroslav@181: jaroslav@114: /** jaroslav@114: * jaroslav@114: * @author Jaroslav Tulach jaroslav@114: */ jaroslav@1493: public class Resources { jaroslav@1493: public static String loadKO() throws IOException { jaroslav@1493: InputStream is = Resources.class.getResourceAsStream("ko.js"); jaroslav@1493: if (is == null) { jaroslav@1493: return "No resource found!"; jaroslav@1493: } jaroslav@1493: byte[] arr = new byte[4092]; jaroslav@1493: int len = is.read(arr); jaroslav@1493: if (len == -1) { jaroslav@1493: return "No data read!"; jaroslav@1493: } jaroslav@1495: final Object str = new String(arr, 0, len, "UTF-8"); jaroslav@1495: return str.toString(); jaroslav@114: } jaroslav@1496: static String loadClazz() throws IOException { jaroslav@1496: InputStream is = Resources.class.getResourceAsStream("Bck2BrwsrToolkit.class"); jaroslav@1496: if (is == null) { jaroslav@1496: return "No resource found!"; jaroslav@1496: } jaroslav@1496: byte[] arr = new byte[4092]; jaroslav@1496: int len = is.read(arr); jaroslav@1496: if (len < 10) { jaroslav@1496: return "No data read! Len: " + len; jaroslav@1496: } jaroslav@1496: jaroslav@1496: StringBuilder sb = new StringBuilder(); jaroslav@1496: sb.append("["); jaroslav@1496: for (int i = 0; i < len; i++) { jaroslav@1496: sb.append(arr[i]).append(", "); jaroslav@1496: } jaroslav@1496: jaroslav@1496: return sb.toString().toString(); jaroslav@1496: } jaroslav@114: }