Java BufferedReader Read loadJCC()

Here you can find the source of loadJCC()

Description

load JCC

License

Open Source License

Declaration

public static void loadJCC() throws Exception 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void loadJCC() throws Exception {
        String base = getJCCPath("python");
        String library = base + "/libjcc.so";
        System.load(library);/* w  w  w  .  ja  v  a2 s  . c o m*/
    }

    /**
     * Runs Python in the console and retrieves the location of the JCC egg
     * 
     * @return
     * @throws Exception 
     */
    public static String getJCCPath(String pythonExec) throws Exception {
        String[] cmd = { pythonExec, "-c", "import os, jcc; print os.path.dirname(os.path.dirname(jcc.__file__))" };
        return execCommand(cmd);
    }

    public static String execCommand(String[] cmd) throws Exception {
        Runtime run = Runtime.getRuntime();
        Process pr = null;
        try {
            pr = run.exec(cmd);
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }
        try {
            pr.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
            throw e;
        }
        BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        String line = null;
        StringBuffer out = new StringBuffer();
        try {
            while ((line = buf.readLine()) != null) {
                out.append(line);
                out.append("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        }
        return out.toString();
    }
}

Related

  1. loadIgnorList()
  2. loadInputStream(InputStream inputStream)
  3. loadInt(BufferedReader br)
  4. loadIntegersFromFile(String filename)
  5. loadIntoString(InputStream is)
  6. loadJson(String path)
  7. loadKey(String filename)
  8. loadLastExpInfo(String lastExpFileName)
  9. loadLine(InputStream load)