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:de.unijena.bioinf.ChemistryBase.chem.utils.PeriodicTableJSONReader.java

private static String readString(Reader reader) throws IOException {
    final StringBuilder buffer = new StringBuilder();
    final BufferedReader bufReader = new BufferedReader(reader);
    try {//from w  w w .  j a v a  2 s .c o  m
        while (bufReader.ready()) {
            buffer.append(bufReader.readLine()).append("\n");
        }
    } finally {
        bufReader.close();
    }
    return buffer.toString();
}

From source file:eu.databata.engine.util.PropagatorRecreateDatabaseTool.java

private static String getFileContent(ClassLoader contextClassLoader, String fileName) throws IOException {
    LOG.info("Loading file '" + fileName + "'");
    InputStream submitFileStream = contextClassLoader.getResourceAsStream(fileName);
    if (submitFileStream == null) {
        LOG.info("File with name '" + fileName
                + "' cannot be read from classpath. Trying to load default submit file.");
        return null;
    }//from w  w w  . j ava2  s  .c om
    InputStreamReader streamReader = new InputStreamReader(submitFileStream);
    BufferedReader bufferedReader = new BufferedReader(streamReader);

    String result = "";
    while (bufferedReader.ready()) {
        result += bufferedReader.readLine();
        result += "\n";
    }

    return result;
}

From source file:org.apache.pdfbox.preflight.Validator_A1b.java

private static List<File> listFiles(String path) throws IOException {
    List<File> files = new ArrayList<File>();
    File f = new File(path);
    if (f.isFile()) {
        FileReader fr = new FileReader(f);
        BufferedReader buf = new BufferedReader(fr);
        while (buf.ready()) {
            File fn = new File(buf.readLine());
            if (fn.exists()) {
                files.add(fn);//from w ww.  j  a v a 2  s. c om
            } // else warn ?
        }
        IOUtils.closeQuietly(buf);
    } else {
        File[] fileList = f.listFiles();
        if (fileList != null) {
            files.addAll(Arrays.asList(fileList));
        }
    }
    return files;
}

From source file:org.archiviststoolkit.importer.ImportUtils.java

public static ArrayList<String> loadFileIntoStringArray(File file)

{
    String line;//from w w w  .  ja  v  a2 s  .  c o  m
    ArrayList<String> array = new ArrayList<String>();

    try {
        BufferedReader in = new BufferedReader(new FileReader(file));

        if (!in.ready())
            throw new IOException();

        while ((line = in.readLine()) != null)
            array.add(line);

        in.close();
    } catch (IOException e) {
        System.out.println(e);
        return null;
    }

    return array;
}

From source file:Main.java

public static String readTextContent(String filePath) {
    BufferedReader reader = null;
    try {/*from w  w  w.  j  a va 2  s. c o  m*/
        reader = new BufferedReader(new FileReader(filePath));
        StringBuilder sb = new StringBuilder();
        while (reader.ready())
            sb.append(reader.readLine());
        return sb.toString();
    } catch (FileNotFoundException e) {
        //            e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}

From source file:br.org.acessobrasil.nucleuSilva.util.ObterPaginaLocal.java

/**
 * Mtodo que extrai o contedo de uma pgina.
 * @param url URL da pgina a ter seu contedo extrado.
 * @return Contedo de uma pgina.//from  w  w  w  .ja v  a2s.  co m
 * @throws IOException Erro ao conectar a pgina.
 * @deprecated Utilize o mtodo getContent().
 */
public static StringBuilder pegar(final URL url) throws IOException {
    //JOptionPane.showMessageDialog(null,"oi1");
    StringBuilder buf = new StringBuilder();
    File file = new File(nomeArquivoOuDiretorio);
    FileReader reader = new FileReader(file);
    BufferedReader leitor = new BufferedReader(reader);

    while (leitor.ready()) {
        buf.append(leitor.readLine() + "\n");
    }

    leitor.close();
    //JOptionPane.showMessageDialog(null,"oi2");
    return buf;
}

From source file:interpolation.Polyfit.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 w  ww .j a va 2 s. c  om*/
        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(), point.getB());
        normalpoints.add(newpoint);
    }

    return normalpoints;
}

From source file:gdv.xport.util.URLReader.java

private static String read(final URLConnection connection) throws IOException {
    connection.connect();//ww  w  .  j  av a 2 s.c o m
    InputStream istream = connection.getInputStream();
    BufferedReader in = new BufferedReader(new InputStreamReader(istream));
    try {
        StringBuilder sbuf = new StringBuilder();
        while (in.ready()) {
            String line = in.readLine();
            LOG.debug(line);
            sbuf.append(line);
            sbuf.append("\n");
        }
        return sbuf.toString().trim();
    } finally {
        in.close();
        istream.close();
    }
}

From source file:org.vosao.utils.StreamUtil.java

public static String getTextResource(ClassLoader classLoader, final String path) throws IOException {
    InputStream in = getResource(classLoader, path);
    if (in == null) {
        throw new IOException("Empty input stream.");
    }//  w  w  w.  j  av  a2s .co m
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuffer buf = new StringBuffer();
    while (reader.ready()) {
        buf.append(reader.readLine()).append("\n");
    }
    return buf.toString();
}

From source file:com.pseudosudostudios.jdd.utils.ScoreSaves.java

/**
 * @param c the application's context that owns the data file
 * @return a List of games saved in the file
 *//* ww w  .j  av  a 2 s  .co  m*/
public static List<Entry> getSaves(Context c) {
    List<Entry> entries = new ArrayList<Entry>();
    File f = new File(c.getFilesDir(), fileName);
    if (!f.exists() || f.isDirectory()) {
        return new ArrayList<Entry>();
    }
    try {
        BufferedReader reader = new BufferedReader(new FileReader(f));
        StringBuffer buff = new StringBuffer();
        while (reader.ready())
            buff.append(reader.readLine());
        reader.close();
        JSONArray array = new JSONArray(buff.toString());
        for (int i = 0; i < array.length(); i++) {
            Entry e = makeEntry(array.getJSONObject(i));
            if (e.getScore() != IGNORE_SCORE)
                entries.add(e);
        }

        Collections.sort(entries);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return entries;
}