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:com.betfair.application.performance.BaselinePerformanceTester.java

private static String getLastLine(File file) throws IOException {

    InputStreamReader streamReader = new InputStreamReader(new FileInputStream(file));

    BufferedReader br = new BufferedReader(streamReader);

    String line = null;/*from   w w w.  jav  a2  s .  c om*/
    while (br.ready()) {
        line = br.readLine();
    }
    return line;
}

From source file:com.github.koraktor.steamcondenser.community.SteamGame.java

/**
 * Checks if a game is up-to-date by reading information from a
 * <code>steam.inf</code> file and comparing it using the Web API
 *
 * @param path The file system path of the `steam.inf` file
 * @return <code>true</code> if the game is up-to-date
 * @throws IOException if the steam.inf cannot be read
 * @throws JSONException if the JSON data is malformed
 * @throws SteamCondenserException if the given steam.inf is invalid or
 *         the Web API request fails//from  w w w  .j av a 2 s .  com
 */
public static boolean checkSteamInf(String path) throws IOException, JSONException, SteamCondenserException {
    BufferedReader steamInf = new BufferedReader(new FileReader(path));
    String steamInfContents = "";

    while (steamInf.ready()) {
        steamInfContents += steamInf.readLine() + "\n";
    }
    steamInf.close();

    Pattern appIdPattern = Pattern.compile("^\\s*appID=(\\d+)\\s*$",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    Matcher appIdMatcher = appIdPattern.matcher(steamInfContents);
    Pattern versionPattern = Pattern.compile("^\\s*PatchVersion=([\\d\\.]+)\\s*$",
            Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
    Matcher versionMatcher = versionPattern.matcher(steamInfContents);

    if (!(appIdMatcher.find() && versionMatcher.find())) {
        throw new SteamCondenserException("The steam.inf file at \"" + path + "\" is invalid.");
    }

    int appId = Integer.parseInt(appIdMatcher.group(1));
    int version = Integer.parseInt(versionMatcher.group(1).replace(".", ""));

    return isUpToDate(appId, version);
}

From source file:org.fiware.apps.repository.it.queryService.QueryServiceITTest.java

@BeforeClass
public static void setUpClass() throws IOException {
    IntegrationTestHelper client = new IntegrationTestHelper();
    Resource resource = IntegrationTestHelper.generateResource(null, "fileName", null, "http://appTest", null,
            "Me", null, null, "queryResourceTest");

    List<Header> headers = new LinkedList<>();
    client.deleteCollection("queryCollection", headers);

    //Create a resource
    headers.add(new BasicHeader("Content-Type", "application/json"));
    HttpResponse response = client.postResourceMeta("queryCollection", client.resourceToJson(resource),
            headers);//from www  .ja va2 s .c o m
    assertEquals(201, response.getStatusLine().getStatusCode());

    String auxString = "";
    FileReader file = new FileReader("src/test/resources/storeRDF.rdf");
    BufferedReader buffer = new BufferedReader(file);
    while (buffer.ready()) {
        auxString = auxString.concat(buffer.readLine() + "\n");
    }
    buffer.close();

    headers = new LinkedList<>();
    headers.add(new BasicHeader("Content-Type", "application/rdf+xml"));
    response = client.putResourceContent("queryCollection/queryResourceTest", auxString, headers);
    assertEquals(200, response.getStatusLine().getStatusCode());
}

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

/**
 * Mtodo que extrai o contedo de uma pgina.
 * //from w  w w.  j a  v  a2  s  .c  om
 * @param url
 *            URL da pgina a ter seu contedo extrado.
 * @return Contedo de uma pgina.
 * @throws IOException
 *             Erro ao conectar a pgina.
 * @deprecated Utilize o mtodo getContent().
 */
public static StringBuilder pegar(final URL url) throws IOException {
    StringBuilder buf = new StringBuilder();
    InputStreamReader isr = new InputStreamReader(url.openStream());
    BufferedReader in = new BufferedReader(isr);
    while (in.ready()) {
        buf.append(in.readLine() + "\n");
    }

    in.close();
    // aqui simplesmente  lido uma pagina da internet e retornada em buf,
    // sem tratamentos
    return buf;
}

From source file:org.fiware.apps.repository.it.collectionService.CollectionServicePutITTest.java

@BeforeClass
public static void setUpClass() throws IOException {
    IntegrationTestHelper client = new IntegrationTestHelper();

    String fileName = "fileNameExample";
    String contentUrl = "http://localhost:8080/contentUrl/resourceTestPut";
    String creator = "Me";
    String name = "resourceTestPut";
    Resource resource = IntegrationTestHelper.generateResource(null, fileName, null, contentUrl, null, creator,
            null, null, name);/*from   w  ww  . j a  v a2s.co m*/

    String auxString = "";
    FileReader file = new FileReader("src/test/resources/rdf+xml.rdf");
    BufferedReader buffer = new BufferedReader(file);
    while (buffer.ready()) {
        auxString = auxString.concat(buffer.readLine());
    }
    buffer.close();
    rdfXmlExample = auxString;

    auxString = "";
    file = new FileReader("src/test/resources/rdf+json.rdf");
    buffer = new BufferedReader(file);
    while (buffer.ready()) {
        auxString = auxString.concat(buffer.readLine());
    }
    buffer.close();
    rdfJsonExample = auxString;

    auxString = "";
    file = new FileReader("src/test/resources/N3.rdf");
    buffer = new BufferedReader(file);
    while (buffer.ready()) {
        auxString = auxString.concat(buffer.readLine());
    }
    buffer.close();
    rdfN3Example = auxString;

    auxString = "";
    file = new FileReader("src/test/resources/turttle.rdf");
    buffer = new BufferedReader(file);
    while (buffer.ready()) {
        auxString = auxString.concat(buffer.readLine());
    }
    buffer.close();
    rdfTurttleExample = auxString;

    dataExample = "Data example with nothing inside.";

    //Delete the collection
    List<Header> headers = new LinkedList<>();
    client.deleteCollection(collection, headers);

    //Create a resource in the repository
    headers.add(new BasicHeader("Content-Type", "application/json"));
    HttpResponse response = client.postResourceMeta(collection, IntegrationTestHelper.resourceToJson(resource),
            headers);
    assertEquals(201, response.getStatusLine().getStatusCode());

    resource.setName(name + "name");
    resource.setContentUrl(contentUrl + name);
    response = client.postResourceMeta(collection, IntegrationTestHelper.resourceToJson(resource), headers);
    assertEquals(201, response.getStatusLine().getStatusCode());
}

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

/**
 * @param clearToolLauncher/*from  w  w w  . j  av a2 s.c o  m*/
 * @param version
 * @return version description
 * @throws IOException
 * @throws InterruptedException
 */
public static String getVersionDescription(ClearTool clearTool, String version, String format)
        throws IOException, InterruptedException {
    Reader rd = clearTool.describe(format, version);
    BufferedReader bufferedReader = new BufferedReader(rd);
    StringBuilder sb = new StringBuilder();
    while (bufferedReader.ready()) {
        sb.append(bufferedReader.readLine());
    }
    return sb.toString();
}

From source file:me.openMap.ApplicationSettings.java

private static ApplicationSettings load() {
    ApplicationSettings rtn = null;//from www  . j a  v  a2s  .  c  om
    StringBuilder fileName = new StringBuilder();

    fileName.append(System.getProperty("user.home"));
    fileName.append(File.separator);
    fileName.append(".");
    fileName.append(ApplicationSettings.class.getSimpleName());
    fileName.append(".xml");

    File fp = new File(fileName.toString());
    if (!fp.exists()) {
        return rtn;
    }

    try {
        BufferedReader in = new BufferedReader(new FileReader(fileName.toString()));
        StringBuilder builder = new StringBuilder();
        while (in.ready()) {
            builder.append(in.readLine());
        }
        in.close();
        XStream stream = new XStream();

        stream.processAnnotations(ApplicationSettings.class);
        stream.processAnnotations(GradientParameters.class);

        Object obj = stream.fromXML(builder.toString());

        rtn = ApplicationSettings.class.cast(obj);

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

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

/**
 * @param clearToolLauncher//from w w w.java  2  s .co  m
 * @param streamName
 * @return list of components - name and isModifiable
 * @throws IOException
 * @throws InterruptedException
 */
public static List<Component> getStreamComponentsDesc(ClearTool clearTool, String streamName)
        throws IOException, InterruptedException {
    List<Component> componentsDescList = new ArrayList<Component>();
    Reader reader = clearTool.describe(null, "stream:" + streamName);
    BufferedReader bufferedReader = new BufferedReader(reader);
    StringBuilder sb = new StringBuilder();
    while (bufferedReader.ready()) {
        sb.append(bufferedReader.readLine());
    }
    String output = sb.toString();

    // searching in the result for the pattern (<component-name> (modifiable | non-modifiable)
    int idx = 0;
    int idx1;
    int idx2;
    String searchFor = "modifiable)";
    while (idx >= 0) {
        idx = output.indexOf(searchFor, idx + 1);

        if (idx > 0) {
            // get the component state part: modifiable or non-modifiable
            idx1 = output.lastIndexOf("(", idx - 1);
            idx2 = output.indexOf(")", idx1);
            String componentState = output.substring(idx1 + 1, idx2);

            // get the component name
            idx1 = output.lastIndexOf("(", idx1 - 1);
            idx2 = output.indexOf(")", idx1);

            // add to the result
            Component componentDesc = new Component(output.substring(idx1 + 1, idx2),
                    componentState.equals("modifiable"));
            componentsDescList.add(componentDesc);
        }
    }

    return componentsDescList;
}

From source file:edu.mayo.cts2.uriresolver.dao.DAOUtiltities.java

public static boolean importMySQLDataToH2Database(DataSource ds) {
    JdbcTemplate jdbcTemplateObject;//  w w  w. j a v  a2s . c  o m
    jdbcTemplateObject = new JdbcTemplate(ds);

    StringBuffer sqlBuffer = new StringBuffer();
    BufferedReader bufferedReader = null;
    Reader reader = null;

    try {
        InputStream in = ResolveURI.class.getResourceAsStream("/uriresolver.sql");
        reader = new InputStreamReader(in, "UTF-8");
        bufferedReader = new BufferedReader(reader);
        while (bufferedReader.ready()) {
            String line = bufferedReader.readLine().trim();
            if (isSQLCode(line)) {
                sqlBuffer.append(convertToH2(line));
            }
        }
        bufferedReader.close();
        reader.close();
    } catch (IOException e) {
        logger.error("Error while importing data to in memory database: " + e.getMessage());
        return false;
    } finally {
        try {
            if (bufferedReader != null) {
                bufferedReader.close();
            }
            if (reader != null) {
                reader.close();
            }
        } catch (IOException ex) {
            logger.error("Error while closing access to in memory database: " + ex.getMessage());
            return true;
        }
    }

    jdbcTemplateObject.execute(sqlBuffer.toString());
    return true;
}

From source file:layer.AutoCoder.java

public static void prepareNextIteration(String input, String output, int iterations, Configuration conf,
        int reduceTasks) {
    String dstName = input + "/cluster" + iterations;
    try {/*from   w  w  w  . j a v  a2s. c om*/
        FileSystem fs = FileSystem.get(conf);
        fs.delete(new Path(dstName), true);
        FSDataOutputStream clusterfile = fs.create(new Path(dstName));

        for (int i = 0; i < reduceTasks; i++) {
            String srcName = output + "/part-r-" + String.format("%05d", i);
            FSDataInputStream cluster = fs.open(new Path(srcName));
            BufferedReader reader = new BufferedReader(new InputStreamReader(cluster));
            while (reader.ready()) {
                String line = reader.readLine() + "\n";
                if (line.length() > 5)
                    clusterfile.write(line.getBytes());
            }
            reader.close();
            cluster.close();
        }
        clusterfile.flush();
        clusterfile.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}