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:mt.Tracking.java

public static ArrayList<Pair<Integer, Double>> loadsimple(final File file) {
    final ArrayList<Pair<Integer, Double>> points = new ArrayList<Pair<Integer, Double>>();
    final ArrayList<Pair<Integer, Double>> normalpoints = new ArrayList<Pair<Integer, Double>>();
    try {/*from   www.  j av a2 s .co  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;
    }

    double maxlength = Double.MIN_VALUE;
    for (Pair<Integer, Double> point : points) {

        double length = point.getB();
        if (length > maxlength)
            maxlength = length;
    }
    for (Pair<Integer, Double> point : points) {
        Pair<Integer, Double> newpoint = new ValuePair<Integer, Double>(point.getA() / 10,
                point.getB() / maxlength);
        normalpoints.add(newpoint);
    }

    return normalpoints;
}

From source file:mt.Tracking.java

public static ArrayList<FLSobject> loadMTStat(final File file) {
    final ArrayList<FLSobject> points = new ArrayList<FLSobject>();

    try {/*from   w  w  w .  j  a  va  2  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[2]);
                final int seedID = (int) Double.parseDouble(split[3]);

                FLSobject statobject = new FLSobject(frame, seedID, length);
                points.add(statobject);
            }
        }
    } catch (Exception e) {

    }

    Collections.sort(points, new Comparator<FLSobject>() {
        @Override
        public int compare(final FLSobject o1, final FLSobject o2) {

            final int t1 = o1.Framenumber;
            final int t2 = o2.Framenumber;

            if (t1 < t2)
                return -1;
            else if (t1 == t2)
                return 0;
            else
                return 1;
        }
    });

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

    else
        return null;
}

From source file:Main.java

public static int getSuVersionCode() {
    Process process = null;/*from  w w  w  .  j  av  a  2 s  .c om*/
    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 && Integer.parseInt(inLine.substring(0, 1)) > 2) {
                inLine = null;
                os.writeBytes("su -V\n");
                inLine = is.readLine();
                if (inLine != null) {
                    return Integer.parseInt(inLine);
                }
            } else {
                return 0;
            }
        } else {
            os.writeBytes("exit\n");
        }
    } catch (IOException e) {
        Log.e(TAG, "Problems reading current version.", e);
        return 0;
    } finally {
        if (process != null) {
            process.destroy();
        }
    }
    return 0;
}

From source file:org.onehippo.forge.jcrshell.console.Terminal.java

public static final void run(InputStream input, OutputStream output) {
    String cr = System.getProperty("line.separator");
    Writer writer = new OutputStreamWriter(output);
    BufferedReader br = new BufferedReader(new InputStreamReader(input));
    try {/*  w  ww .j  a v a 2  s.  c o  m*/
        consoleReader = new ConsoleReader(new FileInputStream(FileDescriptor.in), new PrintWriter(writer), null,
                new UnsupportedTerminal());
        while (br.ready()) {
            String line = br.readLine();
            if (line != null && !line.startsWith("#") && line.trim().length() > 0) {
                writer.append("Executing: ").append(line).append(cr);
                writer.flush();
                try {
                    if (!handleCommand(line)) {
                        writer.append("Command failed, exiting..").append(cr);
                        handleCommand("Exit" + cr);
                        break;
                    }
                } catch (JcrShellShutdownException e) {
                    break;
                }
            }
        }
        writer.append("Finished.").append(cr).flush();
    } catch (IOException e) {
        PrintWriter pw = new PrintWriter(writer);
        e.printStackTrace(pw);
        pw.flush();
    } finally {
        IOUtils.closeQuietly(input);
        IOUtils.closeQuietly(output);
        JcrWrapper.logout();
    }
}

From source file:com.redhat.rhn.testing.TestUtils.java

/**
 * Read whole stream into a string./*from  w  w w.j a  va2s  . c o  m*/
 *
 * @param stream the stream to consume
 * @return the contents of the stream as a string
 * @throws IOException if reading the file fails
 */
public static String readAll(InputStream stream) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
    StringBuffer expected = new StringBuffer();
    while (reader.ready()) {
        expected.append(reader.readLine()).append("\n");
    }
    return expected.toString();
}

From source file:pcgen.util.TestHelper.java

/**
 * Locate the data folder which contains the primary set of LST data. This 
 * defaults to the data folder under the current directory, but can be 
 * customised in the config.ini folder. 
 * @return The path of the data folder./*from  w  w  w . ja  v a2s.c o  m*/
 */
public static String findDataFolder() {
    // Set the pcc location to "data"
    String pccLoc = "data";
    try {
        // Read in options.ini and override the pcc location if it exists
        BufferedReader br = new BufferedReader(
                new InputStreamReader(new FileInputStream("config.ini"), "UTF-8"));
        while (br.ready()) {
            String line = br.readLine();
            if (line != null && line.startsWith("pccFilesPath=")) {
                pccLoc = line.substring(13);
                break;
            }
        }
        br.close();
    } catch (IOException e) {
        // Ignore, see method comment
    }
    return pccLoc;
}

From source file:gov.nist.healthcare.ttt.parsing.Parsing.java

private static String findSoapOfRegistryResponse(String mtom) throws IOException {

    BufferedReader reader = new BufferedReader(new StringReader(mtom));
    StringBuilder sb = new StringBuilder();
    boolean inSoap = false;
    while (reader.ready()) {
        String line = reader.readLine();
        if (line == null) {
            break;
        }/*from   ww  w.j  a v a 2  s  .  c  om*/
        if (line.indexOf("Envelope") != -1) {
            inSoap = true;
        }
        if (inSoap && line.startsWith("--")) {
            break;
        }
        if (inSoap) {
            sb.append(line);
        }

    }
    return sb.toString();

}

From source file:org.dcm4che3.tool.qc.QC.java

private static QCResult sendDeleteRequest(String desc, QC qc) {
    HttpURLConnection connection = null;
    String bfr = "";
    QCResult result = null;//w w  w . ja v a2  s .  c  o m
    try {
        URL url = new URL(adjustDeleteURL(qc).replace(" ", "%20"));
        connection = (HttpURLConnection) url.openConnection();

        connection.setDoOutput(true);

        connection.setDoInput(true);

        connection.setInstanceFollowRedirects(false);

        connection.setRequestMethod("DELETE");

        int responseCode = connection.getResponseCode();
        if (responseCode == 200) {
            InputStream in = connection.getInputStream();

            BufferedReader rdr = new BufferedReader(new InputStreamReader(in));

            while (rdr.ready())
                bfr += rdr.readLine();
        }
        result = new QCResult(desc, bfr, responseCode);
        return result;
    } catch (Exception e) {
        System.out.println("Error preparing request or " + "parsing Server response - " + e);
    }
    return result;

}

From source file:org.dcm4che3.tool.qc.QC.java

private static QCResult sendRequest(String desc, QC qc, Object qcMessage) {

    HttpURLConnection connection = null;
    String bfr = "";
    QCResult result = null;//from   ww w .j av  a  2  s . com
    try {
        URL url = new URL(qc.getUrl());
        connection = (HttpURLConnection) url.openConnection();

        connection.setDoOutput(true);

        connection.setDoInput(true);

        connection.setInstanceFollowRedirects(false);

        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("charset", "utf-8");

        connection.setRequestProperty("Accept", "application/json");

        connection.setUseCaches(false);

        writeMessage(connection, (JsonStructure) qcMessage);

        InputStream in = connection.getInputStream();

        BufferedReader rdr = new BufferedReader(new InputStreamReader(in));
        while (rdr.ready())
            bfr += rdr.readLine();
        result = new QCResult(desc, bfr, connection.getResponseCode());
        return result;
    } catch (Exception e) {
        System.out.println("Error preparing request or " + "parsing Server response - " + e);
    }
    connection.disconnect();
    return result;
}

From source file:gov.nist.healthcare.ttt.parsing.Parsing.java

private static void fixMissingEndBoundry(String mtom) throws IOException {

    BufferedReader reader = new BufferedReader(new StringReader(mtom));
    String line = null;//from  w w w .ja v  a 2s  .com
    String lastLine = null;
    String boundryString = null;
    while (reader.ready()) {
        line = reader.readLine();
        if (line.startsWith("Content-Type:")) {
            int beginBoundry = line.indexOf("boundary=\"");
            String postBoundryBegin = line.substring(beginBoundry + 10);
            System.out.println(postBoundryBegin);
            int endBoundry = postBoundryBegin.indexOf("\"");
            boundryString = postBoundryBegin.substring(0, endBoundry);

            // boundary="MIMEBoundary_1293f28762856bdafcf446f2a6f4a61d95a95d0ad1177f20"
        }
    }
    if (!line.equals(boundryString)) {
        StringBuilder sb = new StringBuilder();
        sb.append(mtom);
        sb.append("\r\n");
        sb.append(boundryString);
    }

}