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:org.apache.qpid.server.security.auth.database.Base64MD5PasswordFilePrincipalDatabaseTest.java

public void testUpdatePasswordIsSavedToFile() {

    File testFile = createPasswordFile(1, 1);

    loadPasswordFile(testFile);/*from  w w  w .  j  av  a  2  s . co  m*/

    Principal testUser = _database.getUser(USERNAME + "0");

    assertNotNull(testUser);

    String NEW_PASSWORD = "guest";
    String NEW_PASSWORD_HASH = "CE4DQ6BIb/BVMN9scFyLtA==";
    try {
        _database.updatePassword(testUser, NEW_PASSWORD.toCharArray());
    } catch (AccountNotFoundException e) {
        fail(e.toString());
    }

    try {
        BufferedReader reader = new BufferedReader(new FileReader(testFile));

        assertTrue("File has no content", reader.ready());

        assertEquals("Comment line has been corrupted.", TEST_COMMENT, reader.readLine());

        assertTrue("File is missing user data.", reader.ready());

        String userLine = reader.readLine();

        String[] result = Pattern.compile(":").split(userLine);

        assertEquals("User line not complete '" + userLine + "'", 2, result.length);

        assertEquals("Username not correct,", USERNAME + "0", result[0]);
        assertEquals("New Password not correct,", NEW_PASSWORD_HASH, result[1]);

        assertFalse("File has more content", reader.ready());

    } catch (IOException e) {
        fail("Unable to valdate file contents due to:" + e.getMessage());
    }
}

From source file:ch.entwine.weblounge.common.impl.util.process.StreamHelper.java

/**
 * Thread run//w  ww  .j av a2s . co m
 */
@Override
public void run() {
    BufferedReader reader = null;
    InputStreamReader isreader = null;
    try {
        if (outputStream != null) {
            writer = new PrintWriter(outputStream);
        }
        isreader = new InputStreamReader(inputStream);
        reader = new BufferedReader(isreader);
        if (reader.ready()) {
            String line = reader.readLine();
            while (keepReading && reader.ready() && line != null) {
                append(line);
                log(line);
                line = reader.readLine();
            }
            if (writer != null)
                writer.flush();
        }
    } catch (IOException ioe) {
        logger.error("Error reading process stream: {}", ioe.getMessage(), ioe);
    } finally {
        IOUtils.closeQuietly(reader);
        IOUtils.closeQuietly(isreader);
        IOUtils.closeQuietly(writer);
    }
}

From source file:mt.RansacFileChooser.java

public void Singlefile() {

    File[] Averagefiles = chooserA.getSelectedFile().listFiles(new FilenameFilter() {

        @Override//from ww w .j  av  a  2  s. c  o  m
        public boolean accept(File pathname, String filename) {

            return (filename.endsWith(".txt") && !filename.contains("Rates") && filename.contains("Average")
                    && !filename.contains("All"));
        }
    });
    File singlefile = new File(
            chooserA.getSelectedFile() + "//" + "Final_Experimental_results" + "All" + ".txt");

    try {
        FileWriter fw = new FileWriter(singlefile);

        BufferedWriter bw = new BufferedWriter(fw);

        bw.write(
                "\tAverageGrowthrate(px)\tAverageShrinkrate(px)\tCatastropheFrequency(px)\tRescueFrequency(px)\n");
        for (int i = 0; i < Averagefiles.length; ++i) {

            File file = Averagefiles[i];

            try {
                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-3].*")) {
                        final String[] split = line.trim().split("\t");

                        final double growthrate = Double.parseDouble(split[0]);
                        final double shrinkrate = Double.parseDouble(split[1]);
                        final double catfrequ = Double.parseDouble(split[2]);
                        final double resfrequ = Double.parseDouble(split[3]);

                        if (growthrate > 0 || shrinkrate < 0 || catfrequ > 0 || resfrequ > 0)
                            bw.write("\t" + (growthrate) + "\t" + "\t" + "\t" + "\t" + (shrinkrate) + "\t"
                                    + "\t" + "\t" + (catfrequ) + "\t" + "\t" + "\t" + (resfrequ)

                                    + "\n" + "\n");

                    }
                }

            }

            catch (Exception e) {
                e.printStackTrace();

            }

        }
        bw.close();
        fw.close();
    }

    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    }

}

From source file:de.indiplex.javapt.JavAPT.java

public void init() throws IOException, URISyntaxException, SQLException {
    fSources = new File("sources.list");
    dDownloads = new File("downloads");
    dTemp = new File("tmp");
    Util.checkFiles(fSources);/*  w w w. jav  a  2 s .c  om*/
    Util.checkDirs(dDownloads, dTemp);

    BufferedReader br = new BufferedReader(new FileReader(fSources));
    while (br.ready()) {
        String line = br.readLine();
        if (!line.equals("")) {
            sourcesURLs.add(line);
        }
    }
    if (!sourcesURLs.contains("http://apt.saurik.com/dists/ios/675.00/main/binary-iphoneos-arm/")) {
        sourcesURLs.add("http://apt.saurik.com/dists/ios/675.00/main/binary-iphoneos-arm/");
    }
    br.close();

    db = new DB();
    db.createDatabaseConnection("jdbc:sqlite:javAPT.db", "reata", "tata");
    Statement stat = db.getStat();
    stat.executeUpdate(SQLite_CREATE_TABLE);
    checkSources();
}

From source file:ubic.gemma.apps.ExpressionExperimentManipulatingCLI.java

/**
 * @param fileName/*from   w  w w .j  a v a  2s.  c  o  m*/
 * @return
 * @throws IOException
 */
private Collection<String> readExpressionExperimentListFileToStrings(String fileName) throws IOException {
    Collection<String> eeNames = new HashSet<String>();
    BufferedReader in = new BufferedReader(new FileReader(fileName));
    while (in.ready()) {
        String eeName = in.readLine().trim();
        if (eeName.startsWith("#")) {
            continue;
        }
        eeNames.add(eeName);
    }
    return eeNames;
}

From source file:org.efaps.esjp.accounting.util.data.ConSis.java

/**
 * Read "P L A N   G E N E R A L   D E   C U E N T A S" from a txt. file/
 *//*  w  w w.  j av  a  2 s. c o  m*/
protected List<Account> readAccounts4Concar(final File _file) throws IOException {
    final BufferedReader in = new BufferedReader(new FileReader(_file));
    final List<Account> ret = new ArrayList<>();
    final Pattern accPattern = Pattern.compile("^(\\d)*");

    while (in.ready()) {
        final String s = in.readLine();
        final Matcher matcher = accPattern.matcher(s);
        matcher.find();
        final String name = matcher.group();
        if (name != null && !name.isEmpty()) {
            matcher.group();
            final String descr = s.substring(13, 50);
            final Account ac = new Account();
            ac.setName(name);
            ac.setDescription(descr);
            ret.add(ac);
        }
    }
    in.close();
    return ret;
}

From source file:edu.uci.ics.jung.io.PajekNetReader.java

/**
 * Returns the first line read from <code>br</code> for which <code>p</code> 
 * returns <code>true</code>, or <code>null</code> if there is no
 * such line./*from  ww w  .  ja  va  2  s.c  o  m*/
 * @throws IOException
 */
protected String skip(BufferedReader br, Predicate<String> p) throws IOException {
    while (br.ready()) {
        String curLine = br.readLine();
        if (curLine == null)
            break;
        curLine = curLine.trim();
        if (p.evaluate(curLine))
            return curLine;
    }
    return null;
}

From source file:org.cytoscape.biopax.internal.BioPaxReaderTask.java

private void createBiopaxSifAttributes(Model model, CyNetwork cyNetwork, File sifNodes, TaskMonitor taskMonitor)
        throws IOException {

    taskMonitor.setStatusMessage("Updating SIF network " + "node/edge attributes from the BioPAX model...");

    //parse the extended sif nodes file into map: "URI" -> other attributes (as a single TSV string)
    Map<String, String> uriToDescriptionMap = new HashMap<String, String>();
    BufferedReader reader = new BufferedReader(new FileReader(sifNodes));
    while (reader.ready()) {
        String line = reader.readLine();
        if (line.trim().isEmpty())
            continue; //skip blank lines if any accidentally present there
        //columns are: URI\tTYPE\tNAME\tUnifXrefs(semicolon-separated)
        String[] cols = line.split("\t");
        assert cols.length == 4 : "BUG: unexpected number of columns (" + cols.length
                + "; must be 4) in the SIF file: " + sifNodes.getAbsolutePath();
        // put into the map
        uriToDescriptionMap.put(cols[0], StringUtils.join(ArrayUtils.remove(cols, 0), '\t'));
    }//from  w  w  w.j  a  va 2 s .c o  m
    reader.close();

    // Set the Quick Find Default Index
    AttributeUtil.set(cyNetwork, cyNetwork, "quickfind.default_index", CyNetwork.NAME, String.class);

    if (cancelled)
        return;

    // Set node/edge attributes from the Biopax Model
    for (CyNode node : cyNetwork.getNodeList()) {
        String uri = cyNetwork.getRow(node).get(CyNetwork.NAME, String.class);
        BioPAXElement e = model.getByID(uri);// can be null (for generic/group nodes)
        if (e instanceof EntityReference || e instanceof Entity) {
            //note: in fact, SIF formatted data contains only ERs, PEs (no sub-classes), and Complexes / Generics.
            BioPaxMapper.createAttributesFromProperties(e, model, node, cyNetwork);
        } else if (e != null) {
            log.warn("SIF network has an unexpected node: " + uri + " of type " + e.getModelInterface());
            BioPaxMapper.createAttributesFromProperties(e, model, node, cyNetwork);
        } else { //e == null; the URI/ID was auto-generated by the sif-converter and not present in the model
            AttributeUtil.set(cyNetwork, node, BioPaxMapper.BIOPAX_URI, uri, String.class);
            //set other attributes from the tmp_biopax2sif_nodes*.sif file
            String sifNodeAttrs = uriToDescriptionMap.get(uri);
            assert (sifNodeAttrs != null && !sifNodeAttrs.isEmpty()) : "Bug: no SIF attributes found for "
                    + uri;
            String[] cols = sifNodeAttrs.split("\t");
            AttributeUtil.set(cyNetwork, node, BioPaxMapper.BIOPAX_ENTITY_TYPE, cols[0], String.class);
            AttributeUtil.set(cyNetwork, node, CyRootNetwork.SHARED_NAME, cols[1], String.class);
            AttributeUtil.set(cyNetwork, node, CyNetwork.NAME, cols[1], String.class);
            if (cols.length > 2) { //no xrefs is possible for some generic nodes
                List<String> xrefs = Arrays.asList(cols[2].split(";"));
                AttributeUtil.set(cyNetwork, node, BioPaxMapper.BIOPAX_RELATIONSHIP, xrefs, String.class);
                AttributeUtil.set(cyNetwork, node, CyNetwork.HIDDEN_ATTRS,
                        BioPaxMapper.BIOPAX_RELATIONSHIP_REFERENCES, xrefs, String.class);
            }
        }
    }
}

From source file:org.eclipse.mylyn.reviews.r4e.upgrade.utils.SimpleFileConverter.java

/**
 * Method convert./*from w w  w  .ja v  a  2  s  .c om*/
 * @param aFile - File
 * @throws FileNotFoundException
 * @throws IOException
 */
protected void convert(File aFile) throws FileNotFoundException, IOException {
    Path path = new Path(aFile.getAbsolutePath());
    if (!aFile.isDirectory() && path.getFileExtension() == null) {
        return;
    }
    for (String ext : fIgnoreExtensions) {
        if (StringUtils.equals(ext, path.getFileExtension())) {
            return;
        }
    }
    if (aFile.exists()) {
        if (aFile.isDirectory()) {
            for (File member : aFile.listFiles()) {
                if (fRecurse || !aFile.isDirectory()) {
                    convert(member);
                }
            }
            //return;
        } else {
            if (path.getFileExtension() == null) {
                return;
            }
            if (path.getFileExtension().equals(fExtension)) {
                log(LINE_FEED + "    " + aFile.getAbsolutePath());
                fFilesConverted++;
                BufferedReader br = new BufferedReader(new FileReader(aFile));
                StringBuilder fileContents = new StringBuilder(8000);
                int lineNum = 0;
                while (br.ready()) {
                    String line = br.readLine();
                    String convert = convert(line);
                    fileContents.append(convert + LINE_FEED);
                    if (!line.equals(convert)) {
                        String lineNumString = StringUtils.leftPad(lineNum + "", 5);
                        log("      " + lineNumString + ":  " + line + LINE_FEED + "              " + convert);
                    }
                    lineNum++;
                }
                br.close();
                BufferedWriter writer = new BufferedWriter(new FileWriter(aFile));
                writer.write(fileContents.toString());
                writer.close();
            }
        }
    }
    fMonitor.worked(1);
}

From source file:de.tudarmstadt.ukp.dkpro.spelling.experiments.hoo2012.io.HOO2012Evaluator.java

private void runProcess(String command) throws Exception {
    ProcessBuilder mProBuilder;//from   ww  w . j  a  v  a  2s.  c om
    Process mProcess;
    BufferedReader mResultReader;

    System.out.println(command);

    mProBuilder = new ProcessBuilder("/bin/sh", "-c", command);
    mProcess = mProBuilder.start();
    mResultReader = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));

    while (!mResultReader.ready()) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    while (mResultReader.ready()) {
        String line = mResultReader.readLine();
        if (line == null)
            throw new IOException("Unexpected end of OutputStream.");

        System.out.println(line);
    }
}