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:uk.co.develop4.security.utils.decoders.DecoderUtils.java

public static String readConsole(long timeout) throws InterruptedException, IOException {
    BufferedReader consoleReader = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Please enter the bootstrap passphrase: ");
    long start = System.currentTimeMillis();
    while (System.currentTimeMillis() - start < timeout) {
        if (!consoleReader.ready()) {
            Thread.sleep(200L);/*from   w  w  w . j  a v  a  2 s.c o m*/
        } else {
            String key = consoleReader.readLine();
            return key;
        }
    }
    return null;
}

From source file:edu.umd.cloud9.example.clustering.IterateGMM.java

public static double getlld(String input, int iterations, Configuration conf) {
    try {//from www  . j  a  v a 2s  . c o m
        FSDataInputStream cluster = FileSystem.get(conf).open(new Path(input + "/cluster" + iterations));
        BufferedReader reader = new BufferedReader(new InputStreamReader(cluster));
        UnivariateGaussianMixtureModel model = new UnivariateGaussianMixtureModel();
        double lld = 0;
        while (reader.ready()) {
            String line = reader.readLine();
            if (line.indexOf("lld") >= 0) {
                String[] terms = line.split("\\s+");
                int j = 0;
                while (j < terms.length) {
                    if (terms[j].indexOf("lld") >= 0)
                        break;
                    j++;
                }
                lld = Double.parseDouble(terms[j + 1]);
                break;
            }
        }
        reader.close();
        cluster.close();
        return lld;
    } catch (IOException exp) {
        exp.printStackTrace();
        return 0;
    }
}

From source file:Emporium.Controle.ContrVpne.java

public static String lerVpne(FileItem item, int idCli, int idDepto, String nomeDepto, String nomeBD)
        throws UnsupportedEncodingException, IOException {
    DecimalFormat df = new DecimalFormat("0.00");

    String ret = "";

    String r_nome = "";
    String r_cpf_cnpj = "";
    String r_cep = "";
    String r_endereco = "";
    String r_numero = "";
    String r_bairro = "";
    String r_cidade = "";// se exiisteir o CEP no DNE
    String r_uf = "";

    String valor = "";

    String d_nome = "";
    String d_cpf_cnpj = "";
    String d_cep = "";
    String d_endereco = "";
    String d_numero = "";
    String d_bairro = "";

    String d_cidade = ""; // se existir na tabela movimentao
    String d_uf = "";

    String descricao = "";
    String sro = "";
    String data = "";

    BufferedReader le = new BufferedReader(new InputStreamReader(item.getInputStream(), "ISO-8859-1"));
    // LE UMA LINHA DO ARQUIVO PARA PULAR O CABEALHO   
    int lineNum = 1;
    while (le.ready()) {
        //LE UMA LINHA DO ARQUIVO 
        String aux = le.readLine();
        //ADICIONA CONTADOR DE LINHA

        if (lineNum == 1) {
            //remetente
            r_nome = aux.substring(38, 88).trim();
            r_cpf_cnpj = aux.substring(98, 112).trim();
            r_cep = aux.substring(112, 120).trim();
            r_endereco = aux.substring(130, 190).trim();
            r_numero = aux.substring(190, 198).trim();
            r_bairro = aux.substring(236, 276).trim();
            try {
                r_numero = Integer.parseInt(r_numero) + "";
            } catch (Exception ex) {
            }// w w  w. ja v a2  s. c o m
        }
        if (lineNum >= 2 && aux.startsWith("DT")) {

            if (item.getName().contains("ValesPagos")) {
                //destinatario
                d_nome = aux.substring(26, 76).trim();
                d_cpf_cnpj = aux.substring(86, 106).trim();//ate106
                d_cep = aux.substring(106, 114).trim();
                d_endereco = aux.substring(124, 184).trim();
                d_numero = aux.substring(184, 230).trim();
                d_bairro = aux.substring(230, 270).trim();
                // String d_cidade;// se exiisteir o CEP no DNE
                // String d_uf;// se exiisteir o CEP no DNE

                sro = aux.substring(306, 319).trim();
                descricao = aux.substring(319, 369).trim();
                valor = aux.substring(298, 306).trim();
                data = aux.substring(369).trim();
            } else {
                //destinatario
                d_nome = aux.substring(26, 76).trim();
                d_cpf_cnpj = aux.substring(86, 100).trim();//ate106
                d_cep = aux.substring(100, 108).trim();
                d_endereco = aux.substring(118, 178).trim();
                d_numero = aux.substring(178, 224).trim();
                d_bairro = aux.substring(224, 264).trim();
                // String d_cidade;// se exiisteir o CEP no DNE
                // String d_uf;// se exiisteir o CEP no DNE

                sro = aux.substring(300, 313).trim();
                descricao = aux.substring(313, 363).trim();
                valor = aux.substring(292, 300).trim();
                data = aux.substring(363).trim();
            }

            try {
                d_numero = Integer.parseInt(d_numero) + "";
            } catch (Exception ex) {
            }
            try {
                valor = df.format((double) Integer.parseInt(valor) / 100) + "";
            } catch (Exception ex) {
            }

            data = data.substring(4, 8) + "-" + data.substring(2, 4) + "-" + data.substring(0, 2);

            Movimentacao mv = getConsultaBySRO(sro, nomeBD);
            if (mv != null) {
                d_uf = mv.getId();// USEI O CAMPO dufF PARA COLOCAR O ID DA MOVIMENTACAO CASO EXISTA
            }
            Endereco end_cep = pesquisaCep(d_cep);
            d_cidade = end_cep.getCidade() + " / " + end_cep.getUf();

            ret += "(" + idCli + "," + idDepto + ",'" + nomeDepto + "','" + sro + "','" + descricao + "','"
                    + valor + "','" + r_nome + "','" + r_cpf_cnpj + "','" + r_endereco + "','" + r_numero
                    + "','" + r_bairro + "','" + r_cidade + "','" + r_uf + "'," + "'" + d_nome + "','"
                    + d_cpf_cnpj + "','" + d_endereco + "','" + d_numero + "','" + d_bairro + "','" + d_cidade
                    + "','" + d_cep + "','" + d_uf + "','" + data + "'),";

        }
        lineNum++;
    }
    le.close();

    return ret;
}

From source file:hudson.plugins.clearcase.ucm.UcmCommon.java

/**
 * @param clearToolLauncher/*from  www.j a  v a  2s  .c om*/
 * @param viewRootDirectory
 * @param bl1
 * @param bl2
 * @return list of versions that were changed between two baselines
 * @throws IOException
 * @throws InterruptedException
 */
public static List<String> getDiffBlVersions(ClearTool clearTool, String viewRootDirectory, String bl1,
        String bl2) throws IOException, InterruptedException {
    Reader rd = clearTool.diffbl(EnumSet.of(DiffBlOptions.VERSIONS), bl1, bl2, viewRootDirectory);

    BufferedReader br = new BufferedReader(rd);

    List<String> versionList = new ArrayList<String>();
    // remove ">>" from result
    for (String line = br.readLine(); br.ready(); line = br.readLine()) {
        if (line.startsWith(">>")) {
            line = line.replaceAll(">>", "");
            versionList.add(line.trim());
        }
    }
    br.close();

    return versionList;
}

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

private static String findContentType(String mtom) throws IOException {
    BufferedReader reader = new BufferedReader(new StringReader(mtom));
    while (reader.ready()) {
        String line = reader.readLine();
        if (line.startsWith("Content-Type:") || line.startsWith("content-type:")) {
            return line.substring(14);
        }// w w w .j a v  a  2 s  .  com
    }
    return null;
}

From source file:com.thejustdo.util.Utils.java

/**
 * Reads the content of a file and returns it in a big string object.
 *
 * @param filename Name and location to the plain file.
 * @return All the lines inside the file.
 *///from   w w w.  j  a  v a 2  s .  c o m
public static String getPlainTextFile(String filename) {
    log.log(Level.INFO, "Loading contents of file: {0}.", filename);
    try {
        StringBuilder answer = new StringBuilder();
        FileReader fr = new FileReader(filename);
        BufferedReader reader = new BufferedReader(fr);

        // while there are more lines.
        String line;
        while (reader.ready()) {
            line = reader.readLine();
            answer.append(line).append("\n");
        }

        // closing resources.
        reader.close();

        return answer.toString();
    } catch (IOException ex) {
        log.log(Level.SEVERE, null, ex);
        return null;
    }
}

From source file:fr.paris.lutece.maven.FileUtils.java

/**
 * Read the last line from the given file
 * @param strFile the file absolute path (ex : /home/filetopath/file.txt)
 * @return the last line, an empty string if the file does not exists
 *//*w w  w. jav  a  2s  .  c o m*/
public static String readLastLine(String strFile) {
    FileInputStream in = null;

    try {
        in = new FileInputStream(strFile);
    } catch (FileNotFoundException e) {
        IOUtils.closeQuietly(in);

        return "";
    }

    String strLastLine = "";
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strTmp = null;

    try {
        while (br.ready()) {
            strTmp = br.readLine();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(in);
    }

    strLastLine = strTmp;

    return strLastLine;
}

From source file:com.thejustdo.util.Utils.java

/**
 * Reads the content of a file and returns it in a big string object.
 *
 * @param filename Name and location to the plain file.
 * @return All the lines inside the file.
 *//*w  w w .j av a  2s.c  o m*/
public static String getPlainTextFileFromContext(String filename) {
    log.log(Level.INFO, "Loading contents of file: {0}.", filename);
    try {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        InputStream is = cl.getResourceAsStream(filename);
        StringBuilder answer = new StringBuilder();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader reader = new BufferedReader(isr);

        // while there are more lines.
        String line;
        while (reader.ready()) {
            line = reader.readLine();
            answer.append(line).append("\n");
        }

        // closing resources.
        reader.close();

        return answer.toString();
    } catch (IOException ex) {
        log.log(Level.SEVERE, null, ex);
        return null;
    }
}

From source file:com.thejustdo.util.Utils.java

/**
 * Reads the content of a file and returns it in a big string object.
 *
 * @param location Name and location to the plain file.
 * @param ctx Context to use.//w  w  w.j av  a  2 s  .c  o m
 * @return
 */
public static String getPlainTextFileFromContext(String location, ServletContext ctx) {
    log.log(Level.INFO, "Loading contents of file: {0} and context: {1}.",
            new Object[] { location, ctx.getContextPath() });
    try {
        InputStream is = ctx.getResourceAsStream(location);
        StringBuilder answer = new StringBuilder();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader reader = new BufferedReader(isr);

        // while there are more lines.
        String line;
        while (reader.ready()) {
            line = reader.readLine();
            answer.append(line).append("\n");
        }

        // closing resources.
        reader.close();

        return answer.toString();
    } catch (IOException ex) {
        log.log(Level.SEVERE, null, ex);
        return null;
    }
}

From source file:org.kalypso.gml.processes.constDelaunay.TriangleExe.java

public static List<GM_Triangle> parseTriangleElementOutput(final BufferedReader eleReader, final String crs,
        final GM_Position[] points) throws IOException {
    final List<GM_Triangle> surfaces = new ArrayList<>();

    eleReader.readLine(); // ignore first line
    while (eleReader.ready()) {
        final String string = eleReader.readLine();
        if (string == null)
            break;

        if (string.startsWith("#")) //$NON-NLS-1$
            continue;

        final StringTokenizer tokenizer = new StringTokenizer(string);
        tokenizer.nextToken(); // ele id - ignore
        final int p1 = Integer.parseInt(tokenizer.nextToken());
        final int p2 = Integer.parseInt(tokenizer.nextToken());
        final int p3 = Integer.parseInt(tokenizer.nextToken());

        final GM_Triangle surface = GeometryFactory.createGM_Triangle(points[p1], points[p2], points[p3], crs);

        surfaces.add(surface);/*from   w  ww.  j  av a2 s  .c o m*/

    }
    return surfaces;
}