rt/vm/src/test/java/org/apidesign/vm4brwsr/Resources.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 28 Apr 2014 17:31:29 +0200
branchclosure
changeset 1496 d3df935aff70
parent 1495 d5dd07b45f79
child 1497 daa5f903b529
permissions -rw-r--r--
Handles resources with non 7-bit ASCII characters
jaroslav@114
     1
/**
jaroslav@114
     2
 * Back 2 Browser Bytecode Translator
jaroslav@114
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@114
     4
 *
jaroslav@114
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@114
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@114
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@114
     8
 *
jaroslav@114
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@114
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@114
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@114
    12
 * GNU General Public License for more details.
jaroslav@114
    13
 *
jaroslav@114
    14
 * You should have received a copy of the GNU General Public License
jaroslav@114
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@114
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@114
    17
 */
jaroslav@114
    18
package org.apidesign.vm4brwsr;
jaroslav@114
    19
jaroslav@181
    20
import java.io.IOException;
jaroslav@1493
    21
import java.io.InputStream;
jaroslav@181
    22
jaroslav@114
    23
/**
jaroslav@114
    24
 *
jaroslav@114
    25
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@114
    26
 */
jaroslav@1493
    27
public class Resources {
jaroslav@1493
    28
    public static String loadKO() throws IOException {
jaroslav@1493
    29
        InputStream is = Resources.class.getResourceAsStream("ko.js");
jaroslav@1493
    30
        if (is == null) {
jaroslav@1493
    31
            return "No resource found!";
jaroslav@1493
    32
        }
jaroslav@1493
    33
        byte[] arr = new byte[4092];
jaroslav@1493
    34
        int len = is.read(arr);
jaroslav@1493
    35
        if (len == -1) {
jaroslav@1493
    36
            return "No data read!";
jaroslav@1493
    37
        }
jaroslav@1495
    38
        final Object str = new String(arr, 0, len, "UTF-8");
jaroslav@1495
    39
        return str.toString();
jaroslav@114
    40
    }
jaroslav@1496
    41
    static String loadClazz() throws IOException {
jaroslav@1496
    42
        InputStream is = Resources.class.getResourceAsStream("Bck2BrwsrToolkit.class");
jaroslav@1496
    43
        if (is == null) {
jaroslav@1496
    44
            return "No resource found!";
jaroslav@1496
    45
        }
jaroslav@1496
    46
        byte[] arr = new byte[4092];
jaroslav@1496
    47
        int len = is.read(arr);
jaroslav@1496
    48
        if (len < 10) {
jaroslav@1496
    49
            return "No data read! Len: " + len;
jaroslav@1496
    50
        }
jaroslav@1496
    51
        
jaroslav@1496
    52
        StringBuilder sb = new StringBuilder();
jaroslav@1496
    53
        sb.append("[");
jaroslav@1496
    54
        for (int i = 0; i < len; i++) {
jaroslav@1496
    55
            sb.append(arr[i]).append(", ");
jaroslav@1496
    56
        }
jaroslav@1496
    57
        
jaroslav@1496
    58
        return sb.toString().toString();
jaroslav@1496
    59
    }
jaroslav@114
    60
}