Search in sources :

Example 76 with FileReader

use of java.io.FileReader in project XobotOS by xamarin.

the class GenerateGLES method emit.

private static void emit(GLESCodeEmitter emitter, BufferedReader specReader, PrintStream glStream, PrintStream cStream) throws Exception {
    String s = null;
    while ((s = specReader.readLine()) != null) {
        if (s.trim().startsWith("//")) {
            continue;
        }
        CFunc cfunc = CFunc.parseCFunc(s);
        String fname = cfunc.getName();
        String stubRoot = "stubs/gles11/" + fname;
        String javaPath = stubRoot + ".java";
        File f = new File(javaPath);
        if (f.exists()) {
            System.out.println("Special-casing function " + fname);
            copy(javaPath, glStream);
            copy(stubRoot + ".cpp", cStream);
            // Register native function names
            // This should be improved to require fewer discrete files
            String filename = stubRoot + ".nativeReg";
            BufferedReader br = new BufferedReader(new FileReader(filename));
            String nfunc;
            while ((nfunc = br.readLine()) != null) {
                emitter.addNativeRegistration(nfunc);
            }
        } else {
            emitter.emitCode(cfunc, s);
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File)

Example 77 with FileReader

use of java.io.FileReader in project XobotOS by xamarin.

the class GenerateGLES method main.

public static void main(String[] args) throws Exception {
    int aidx = 0;
    while ((aidx < args.length) && (args[aidx].charAt(0) == '-')) {
        switch(args[aidx].charAt(1)) {
            default:
                System.err.println("Unknown flag: " + args[aidx]);
                System.exit(1);
        }
        aidx++;
    }
    BufferedReader checksReader = new BufferedReader(new FileReader("specs/gles11/checks.spec"));
    ParameterChecker checker = new ParameterChecker(checksReader);
    // Generate files
    for (String suffix : new String[] { "GLES10", "GLES10Ext", "GLES11", "GLES11Ext", "GLES20" }) {
        BufferedReader spec11Reader = new BufferedReader(new FileReader("specs/gles11/" + suffix + ".spec"));
        String gl11Filename = "android/opengl/" + suffix + ".java";
        String gl11cFilename = "android_opengl_" + suffix + ".cpp";
        PrintStream gl11Stream = new PrintStream(new FileOutputStream("out/" + gl11Filename));
        PrintStream gl11cStream = new PrintStream(new FileOutputStream("out/" + gl11cFilename));
        gl11Stream.println("/*");
        gl11cStream.println("/*");
        copy("stubs/gles11/" + suffix + "Header.java-if", gl11Stream);
        copy("stubs/gles11/" + suffix + "cHeader.cpp", gl11cStream);
        GLESCodeEmitter emitter = new GLESCodeEmitter("android/opengl/" + suffix, checker, gl11Stream, gl11cStream);
        emit(emitter, spec11Reader, gl11Stream, gl11cStream);
        emitter.emitNativeRegistration("register_android_opengl_jni_" + suffix);
        gl11Stream.println("}");
        gl11Stream.close();
        gl11cStream.close();
    }
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 78 with FileReader

use of java.io.FileReader in project XobotOS by xamarin.

the class XStreamUtils method read.

public static <T extends IConfigurationFile> T read(String fileName, Class<T> klass) {
    try {
        FileReader reader = new FileReader(fileName);
        XStream xstream = prepareXStream();
        xstream.setMode(XStream.ID_REFERENCES);
        return klass.cast(xstream.fromXML(reader));
    } catch (FileNotFoundException e) {
        throw new RuntimeException("Cannot read configuration file: " + fileName);
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader)

Example 79 with FileReader

use of java.io.FileReader in project XobotOS by xamarin.

the class GenerateGL method main.

public static void main(String[] args) throws Exception {
    String classPathName = "com/google/android/gles_jni/GLImpl";
    boolean useContextPointer = true;
    int aidx = 0;
    while (args[aidx].charAt(0) == '-') {
        switch(args[aidx].charAt(1)) {
            case 'c':
                useContextPointer = false;
                break;
            default:
                System.err.println("Unknown flag: " + args[aidx]);
                System.exit(1);
        }
        aidx++;
    }
    System.out.println("useContextPointer = " + useContextPointer);
    BufferedReader spec10Reader = new BufferedReader(new FileReader(args[aidx++]));
    BufferedReader spec10ExtReader = new BufferedReader(new FileReader(args[aidx++]));
    BufferedReader spec11Reader = new BufferedReader(new FileReader(args[aidx++]));
    BufferedReader spec11ExtReader = new BufferedReader(new FileReader(args[aidx++]));
    BufferedReader spec11ExtPackReader = new BufferedReader(new FileReader(args[aidx++]));
    BufferedReader checksReader = new BufferedReader(new FileReader(args[aidx++]));
    String gl10Filename = "javax/microedition/khronos/opengles/GL10.java";
    String gl10ExtFilename = "javax/microedition/khronos/opengles/GL10Ext.java";
    String gl11Filename = "javax/microedition/khronos/opengles/GL11.java";
    String gl11ExtFilename = "javax/microedition/khronos/opengles/GL11Ext.java";
    String gl11ExtPackFilename = "javax/microedition/khronos/opengles/GL11ExtensionPack.java";
    String glImplFilename = "com/google/android/gles_jni/GLImpl.java";
    String cFilename = "com_google_android_gles_jni_GLImpl.cpp";
    PrintStream gl10Stream = new PrintStream(new FileOutputStream("out/" + gl10Filename));
    PrintStream gl10ExtStream = new PrintStream(new FileOutputStream("out/" + gl10ExtFilename));
    PrintStream gl11Stream = new PrintStream(new FileOutputStream("out/" + gl11Filename));
    PrintStream gl11ExtStream = new PrintStream(new FileOutputStream("out/" + gl11ExtFilename));
    PrintStream gl11ExtPackStream = new PrintStream(new FileOutputStream("out/" + gl11ExtPackFilename));
    PrintStream glImplStream = new PrintStream(new FileOutputStream("out/" + glImplFilename));
    PrintStream cStream = new PrintStream(new FileOutputStream("out/" + cFilename));
    ParameterChecker checker = new ParameterChecker(checksReader);
    CodeEmitter emitter = new Jsr239CodeEmitter(classPathName, checker, gl10Stream, gl10ExtStream, gl11Stream, gl11ExtStream, gl11ExtPackStream, glImplStream, cStream, useContextPointer);
    gl10Stream.println("/* //device/java/android/" + gl10Filename);
    gl10ExtStream.println("/* //device/java/android/" + gl10ExtFilename);
    gl11Stream.println("/* //device/java/android/" + gl11Filename);
    gl11ExtStream.println("/* //device/java/android/" + gl11ExtFilename);
    gl11ExtPackStream.println("/* //device/java/android/" + gl11ExtPackFilename);
    glImplStream.println("/* //device/java/android/" + glImplFilename);
    cStream.println("/* //device/libs/android_runtime/" + cFilename);
    copy("stubs/jsr239/GL10Header.java-if", gl10Stream);
    copy("stubs/jsr239/GL10ExtHeader.java-if", gl10ExtStream);
    copy("stubs/jsr239/GL11Header.java-if", gl11Stream);
    copy("stubs/jsr239/GL11ExtHeader.java-if", gl11ExtStream);
    copy("stubs/jsr239/GL11ExtensionPackHeader.java-if", gl11ExtPackStream);
    copy("stubs/jsr239/GLImplHeader.java-impl", glImplStream);
    copy("stubs/jsr239/GLCHeader.cpp", cStream);
    emit(0, false, false, emitter, spec10Reader, gl10Stream, glImplStream, cStream);
    emit(0, true, false, emitter, spec10ExtReader, gl10ExtStream, glImplStream, cStream);
    emit(1, false, false, emitter, spec11Reader, gl11Stream, glImplStream, cStream);
    emit(1, true, false, emitter, spec11ExtReader, gl11ExtStream, glImplStream, cStream);
    emit(1, true, true, emitter, spec11ExtPackReader, gl11ExtPackStream, glImplStream, cStream);
    emitter.emitNativeRegistration();
    gl10Stream.println("}");
    gl10ExtStream.println("}");
    gl11Stream.println("}");
    gl11ExtStream.println("}");
    gl11ExtPackStream.println("}");
    glImplStream.println("}");
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 80 with FileReader

use of java.io.FileReader in project VitamioBundle by yixia.

the class CPU method getFeature.

public static int getFeature() {
    if (cachedFeature > 0)
        return getCachedFeature();
    cachedFeature = FEATURE_ARM_V5TE;
    if (cpuinfo.isEmpty()) {
        BufferedReader bis = null;
        try {
            bis = new BufferedReader(new FileReader(new File("/proc/cpuinfo")));
            String line;
            String[] pairs;
            while ((line = bis.readLine()) != null) {
                if (!line.trim().equals("")) {
                    pairs = line.split(":");
                    if (pairs.length > 1)
                        cpuinfo.put(pairs[0].trim(), pairs[1].trim());
                }
            }
        } catch (Exception e) {
            Log.e("getCPUFeature", e);
        } finally {
            try {
                if (bis != null)
                    bis.close();
            } catch (IOException e) {
                Log.e("getCPUFeature", e);
            }
        }
    }
    if (!cpuinfo.isEmpty()) {
        for (String key : cpuinfo.keySet()) Log.d("%s:%s", key, cpuinfo.get(key));
        boolean hasARMv6 = false;
        boolean hasARMv7 = false;
        String val = cpuinfo.get("CPU architecture");
        if (!TextUtils.isEmpty(val)) {
            try {
                int i = StringUtils.convertToInt(val);
                Log.d("CPU architecture: %s", i);
                if (i >= 7) {
                    hasARMv6 = true;
                    hasARMv7 = true;
                } else if (i >= 6) {
                    hasARMv6 = true;
                    hasARMv7 = false;
                }
            } catch (NumberFormatException ex) {
                Log.e("getCPUFeature", ex);
            }
            val = cpuinfo.get("Processor");
            if (TextUtils.isEmpty(val)) {
                val = cpuinfo.get("model name");
            }
            if (val != null && (val.contains("(v7l)") || val.contains("ARMv7"))) {
                hasARMv6 = true;
                hasARMv7 = true;
            }
            if (val != null && (val.contains("(v6l)") || val.contains("ARMv6"))) {
                hasARMv6 = true;
                hasARMv7 = false;
            }
            if (hasARMv6)
                cachedFeature |= FEATURE_ARM_V6;
            if (hasARMv7)
                cachedFeature |= FEATURE_ARM_V7A;
            val = cpuinfo.get("Features");
            if (val != null) {
                if (val.contains("neon"))
                    cachedFeature |= FEATURE_ARM_VFP | FEATURE_ARM_VFPV3 | FEATURE_ARM_NEON;
                else if (val.contains("vfpv3"))
                    cachedFeature |= FEATURE_ARM_VFP | FEATURE_ARM_VFPV3;
                else if (val.contains("vfp"))
                    cachedFeature |= FEATURE_ARM_VFP;
            }
        } else {
            String vendor_id = cpuinfo.get("vendor_id");
            String mips = cpuinfo.get("cpu model");
            if (!TextUtils.isEmpty(vendor_id) && vendor_id.contains("GenuineIntel")) {
                cachedFeature |= FEATURE_X86;
            } else if (!TextUtils.isEmpty(mips) && mips.contains("MIPS")) {
                cachedFeature |= FEATURE_MIPS;
            }
        }
    }
    return getCachedFeature();
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Aggregations

FileReader (java.io.FileReader)1873 BufferedReader (java.io.BufferedReader)1289 IOException (java.io.IOException)893 File (java.io.File)811 FileNotFoundException (java.io.FileNotFoundException)304 ArrayList (java.util.ArrayList)274 Test (org.junit.Test)197 FileWriter (java.io.FileWriter)148 HashMap (java.util.HashMap)116 Reader (java.io.Reader)99 BufferedWriter (java.io.BufferedWriter)98 Properties (java.util.Properties)66 InputStreamReader (java.io.InputStreamReader)64 LineNumberReader (java.io.LineNumberReader)61 Matcher (java.util.regex.Matcher)61 Map (java.util.Map)59 List (java.util.List)56 PrintWriter (java.io.PrintWriter)51 StringTokenizer (java.util.StringTokenizer)51 HashSet (java.util.HashSet)50