Example usage for java.io BufferedReader ready

List of usage examples for java.io BufferedReader ready

Introduction

In this page you can find the example usage for java.io BufferedReader ready.

Prototype

public boolean ready() throws IOException 

Source Link

Document

Tells whether this stream is ready to be read.

Usage

From source file:edu.wpi.margrave.SQSReader.java

protected static MPolicy loadSQS(String polId, String sFileName) throws MUserException {
    // Convert filename
    sFileName = MPolicy.convertSeparators(sFileName);

    // Read in the JSON text

    BufferedReader reader;
    try {/*from   ww w .  j av  a2 s .  co  m*/
        reader = new BufferedReader(new FileReader(sFileName));
        StringBuffer target = new StringBuffer();
        while (reader.ready()) {
            String line = reader.readLine();
            target.append(line + "\n");
        }
        reader.close();

        JSONObject json = new JSONObject(target.toString());

        // Use provided policy ID
        //String polId;         
        //if(!json.isNull("Id"))
        //   polId = json.getString("Id");
        //else
        //   throw new MGEUnsupportedSQS("Id element must be present.");

        MVocab env = createSQSVocab(polId);
        MPolicyLeaf result = new MPolicyLeaf(polId, env);

        result.declareVariable("p", "Principal");
        result.declareVariable("a", "Action");
        result.declareVariable("r", "Resource");
        result.declareVariable("c", "Condition");

        // Get statements; may be an array or a single statement object.
        Object statement_s = json.get("Statement");
        if (statement_s instanceof JSONArray) {
            JSONArray statements = json.getJSONArray("Statement");

            for (int ii = 0; ii < statements.length(); ii++) {
                JSONObject thisStatement = statements.getJSONObject(ii);
                handleSQSStatement(thisStatement, result, ii);
            }
        } else
            handleSQSStatement((JSONObject) statement_s, result, 0);

        // "Allow overrides a `default deny' but never an explicit deny."
        // Default deny is N/a.
        Set<String> denySet = new HashSet<String>();
        denySet.add("Deny");
        result.rCombineWhatOverrides.put("Allow", denySet); // Allow < {Deny}

        result.initIDBs();

        return result;

    } catch (IOException e) {
        throw new MGEUnsupportedSQS(e.toString());
    } catch (JSONException e) {
        throw new MGEUnsupportedSQS(e.toString());
    }

}

From source file:gestionale.persistence.DAOCliente.java

public static String comuniItaliani(String comune, String provincia) {
    File file = new File("comuni.txt");
    int contatore = 0;
    try {//from   w  ww  .  java  2 s  . co  m
        BufferedReader br = new BufferedReader(new FileReader(file));
        try {
            //boolean stato = true;
            String temp = br.readLine();
            while (br.ready()) {
                contatore++;
                try {
                    String nomeCitta = temp.substring(0, 35);
                    String nomeProvincia = temp.substring(35, 38);
                    if (nomeCitta.contains(comune.toUpperCase())
                            && nomeProvincia.contains(provincia.toUpperCase())) {
                        //System.out.println(temp.substring(69, 74));
                        return temp.substring(69, 74);
                    } else {
                        temp = br.readLine();
                    }

                } catch (IOException ex) {
                    Logger.getLogger(DAOCliente.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            br.close();
        } catch (IOException ex) {
            Logger.getLogger(DAOCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(DAOCliente.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:de.bps.onyx.plugin.OnyxModule.java

public static boolean isOnyxTest(File zipfile) {
    // <OLTACE-72>
    File unzippedDir = null;//from   ww w .j  a  v a 2  s.com
    if (zipfile.getName().toLowerCase().endsWith(".zip")) {
        unzippedDir = new File(
                zipfile.getAbsolutePath().substring(0, zipfile.getAbsolutePath().length() - 4) + "__unzipped");
        if (!unzippedDir.exists()) {
            unzippedDir.mkdir();
        }
        ZipUtil.unzip(zipfile, unzippedDir);
        zipfile = unzippedDir;
    }
    // </OLTACE-72>
    BufferedReader br = null;
    try {
        File mani = new File(zipfile.getAbsolutePath() + "/imsmanifest.xml");
        br = new BufferedReader(new FileReader(mani));
        while (br.ready()) {
            String l = br.readLine();
            if (l.indexOf("imsqti_xmlv2p1") != -1 || l.indexOf("imsqti_test_xmlv2p1") != -1
                    || l.indexOf("imsqti_assessment_xmlv2p1") != -1) {
                br.close();
                // <OLTACE-72>
                if (unzippedDir != null) {
                    unzippedDir.delete();
                }
                // </OLTACE-72>
                return true;
            }
        }
        br.close();
    } catch (Exception e) {
        IOUtils.closeQuietly(br);
    }
    // <OLTACE-72>
    if (unzippedDir != null) {
        unzippedDir.delete();
    }
    // </OLTACE-72>
    return false;

}

From source file:modnlp.capte.AlignerUtils.java

public static void convertLineEndings(String inputfile, String outputfile) {
    /* This is a quick hackaround to convert the line endings from
     *  Windows files into Unix line endings so that the sentence splitter will work
     *  Seems to work, but hasn't been extensively tested.
     *//*w ww  .  j a va2  s. co m*/
    try {
        File input = new File(inputfile);
        File output = new File(outputfile);
        BufferedReader bb = new BufferedReader(new InputStreamReader(new FileInputStream(inputfile), "UTF8"));
        PrintWriter bv = new PrintWriter(new OutputStreamWriter(new FileOutputStream(outputfile), "UTF8"));
        String l = "";
        while (bb.ready()) {
            l = bb.readLine();
            bv.write(l + "\n");
        }

        bb.close();
        bv.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:mt.Tracking.java

public static double[] loadCalibration(final File file) {

    double[] calibrations = new double[3];
    double calibrationX = 1, calibrationY = 1, calibrationT = 1;
    try {//ww  w  . j  a va2s  .  c o m
        BufferedReader in = Util.openFileRead(file);

        while (in.ready()) {
            String line = in.readLine().trim();

            while (line.contains("\t\t"))
                line = line.replaceAll("\t\t", "\t");

            if (line.length() >= 3 && line.matches("[0-9].*")) {
                final String[] split = line.trim().split("\t");

                calibrationX = Double.parseDouble(split[10]);
                calibrationY = Double.parseDouble(split[11]);
                calibrationT = Double.parseDouble(split[12]);

            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    calibrations[0] = calibrationX;
    calibrations[1] = calibrationY;
    calibrations[2] = calibrationT;

    return calibrations;
}

From source file:teste.Teste.java

public static ArrayList<String> getUserBlocks(String path) {
    ArrayList<String> userblocks = new ArrayList<>();
    System.out.println("Usurios Banidos:   ");
    File arquivo = new File(path);
    try {/*from   w w  w .  java  2s.  c  o m*/
        FileReader MeuArquivo = new FileReader(arquivo);
        BufferedReader br = new BufferedReader(MeuArquivo);

        while (br.ready()) {

            String linha = br.readLine();
            userblocks.add(linha);
            System.out.println("\t" + linha);
        }
    } catch (IOException e) {

        System.out.println("no foi possvel ler a lista de usuarios banidos");
    }

    return userblocks;
}

From source file:Main.java

public static String getSuVersion() {
    Process process = null;//  www .jav a  2  s  . c  o m
    String inLine = null;

    try {
        process = Runtime.getRuntime().exec("sh");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        BufferedReader is = new BufferedReader(
                new InputStreamReader(new DataInputStream(process.getInputStream())), 64);
        os.writeBytes("su -v\n");

        // We have to hold up the thread to make sure that we're ready to read
        // the stream, using increments of 5ms makes it return as quick as
        // possible, and limiting to 1000ms makes sure that it doesn't hang for
        // too long if there's a problem.
        for (int i = 0; i < 400; i++) {
            if (is.ready()) {
                break;
            }
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                Log.w(TAG, "Sleep timer got interrupted...");
            }
        }
        if (is.ready()) {
            inLine = is.readLine();
            if (inLine != null) {
                return inLine;
            }
        } else {
            os.writeBytes("exit\n");
        }
    } catch (IOException e) {
        Log.e(TAG, "Problems reading current version.", e);
        return null;
    } finally {
        if (process != null) {
            process.destroy();
        }
    }

    return null;
}

From source file:mt.Tracking.java

public static ArrayList<Pair<Integer, Double>> loadMT(final File file) {
    final ArrayList<Pair<Integer, Double>> points = new ArrayList<Pair<Integer, Double>>();

    try {// w w w .j a v a2 s  .  c  o  m
        BufferedReader in = Util.openFileRead(file);

        while (in.ready()) {
            String line = in.readLine().trim();

            while (line.contains("\t\t"))
                line = line.replaceAll("\t\t", "\t");

            if (line.length() >= 3 && line.matches("[0-9].*")) {
                final String[] split = line.trim().split("\t");

                final int frame = (int) Double.parseDouble(split[0]);
                final double length = Double.parseDouble(split[1]);

                points.add(new ValuePair<Integer, Double>(frame, length));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    Collections.sort(points, new Comparator<Pair<Integer, Double>>() {
        @Override
        public int compare(final Pair<Integer, Double> o1, final Pair<Integer, Double> o2) {
            return o1.getA().compareTo(o2.getA());
        }
    });

    if (points.size() > 0)
        return points;

    else
        return null;
}

From source file:com.netscape.cmsutil.util.Utils.java

public static void copy(String orig, String dest) throws Exception {
    BufferedReader in = null;
    PrintWriter out = null;//  w  w  w  . j  a  v a  2s  . c  o  m
    try {
        in = new BufferedReader(new FileReader(orig));
        out = new PrintWriter(new BufferedWriter(new FileWriter(dest)));
        String line = "";
        while (in.ready()) {
            line = in.readLine();
            if (line != null)
                out.println(line);
        }
    } catch (Exception ee) {
        ee.printStackTrace();
        throw ee;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (out != null) {
            out.close();
        }
    }
}

From source file:teste.Teste.java

public static Map<String, String> getConfigurations(String path) {
    Map<String, String> tempConfigurations = new HashMap<>();

    File arquivo = new File(path);
    try {/*from w  w  w. j a va  2 s  .  c  o m*/
        FileReader MeuArquivo = new FileReader(arquivo);
        BufferedReader br = new BufferedReader(MeuArquivo);

        while (br.ready()) {

            String linha = br.readLine().toLowerCase();

            String colunas[] = linha.split(";");

            tempConfigurations.put(colunas[0].toUpperCase(), colunas[1]);

        }
    } catch (IOException e) {
        e.printStackTrace();
        System.out.println(
                "Arquivo configurations.txt no est presente ou no est no padro.\nTente: \nCLIENT_ID;9cd1f78e9e424b109489a9efc87c1638\n"
                        + "\nCLIENT_SECRET;9894688d6b344b0e90ef9c887135abd8\n"
                        + "\naccess_token;144397518.1fb235f.b81ed940c95245d7995ef661f0618afe");
    }

    return tempConfigurations;
}