Search in sources :

Example 36 with BufferedReader

use of java.io.BufferedReader in project commons by twitter.

the class FileEchoer method echo.

@Override
public String echo() throws IOException {
    Closer closer = Closer.create();
    try {
        FileReader fileReader = closer.register(new FileReader("/etc/hosts"));
        BufferedReader bufferedReader = closer.register(new BufferedReader(fileReader));
        return bufferedReader.readLine();
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 37 with BufferedReader

use of java.io.BufferedReader in project skype-java-api by taksan.

the class CSVPlayer method init.

protected void init() {
    if (reader != null) {
        destory();
    }
    InputStream csvStream = getClass().getResourceAsStream(file.getPath().replace("\\", "/"));
    if (csvStream == null)
        throw new IllegalStateException("The CSV file " + file.getAbsolutePath() + " was not found.");
    reader = new BufferedReader(new InputStreamReader(csvStream));
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader)

Example 38 with BufferedReader

use of java.io.BufferedReader in project Rutgers-Course-Tracker by tevjef.

the class Utils method parseResource.

public static String parseResource(Context context, int resource) throws IOException {
    InputStream is = context.getResources().openRawResource(resource);
    Writer writer = new StringWriter();
    char[] buffer = new char[1024];
    try {
        Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        int n;
        while ((n = reader.read(buffer)) != -1) {
            writer.write(buffer, 0, n);
        }
    } finally {
        is.close();
    }
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 39 with BufferedReader

use of java.io.BufferedReader in project titan by thinkaurelius.

the class GraphOfTheGodsCompatIT method testOpenAndQueryCompatibleDatabaseFiles.

/**
     * Download and open databases created by previous versions of Titan.
     * A basic check for cluster-restart forward-compatibility.
     */
@Test
public void testOpenAndQueryCompatibleDatabaseFiles() throws Exception {
    String compatManifest = Joiner.on(File.separator).join("target", "test-classes", "compat.csv");
    BufferedReader compatReader = null;
    int lineNumber = 0;
    int tested = 0;
    try {
        log.info("Opening compat manifest: {}", compatManifest);
        compatReader = new BufferedReader(new FileReader(compatManifest));
        String l;
        while (null != (l = compatReader.readLine())) {
            lineNumber++;
            String[] tokens = l.split(",");
            if (3 != tokens.length) {
                log.warn("Ignoring line {} (splitting on commas yielded {} tokens instead of the expected {}): {}", lineNumber, tokens.length, 3, l);
                continue;
            }
            String version = tokens[0].trim();
            String config = tokens[1].trim();
            String archiveurl = tokens[2].trim();
            if (version.isEmpty()) {
                log.warn("Ignoring line {} due to empty version field", lineNumber);
                continue;
            }
            if (config.isEmpty()) {
                log.warn("Ignoring line {} due to empty config field", lineNumber);
                continue;
            }
            if (archiveurl.isEmpty()) {
                log.warn("Ignoring line {} due to empty archiveurl field", lineNumber);
                continue;
            }
            if (!config.equals(BDB_ES)) {
                log.warn("Ignoring line {} with unknown config string {} (only {} is supported)", lineNumber, config, BDB_ES);
            }
            downloadAndTest(archiveurl);
            tested++;
        }
    } finally {
        IOUtils.closeQuietly(compatReader);
    }
    log.info("Read compat manifest with {} lines ({} tested, {} ignored)", lineNumber, tested, lineNumber - tested);
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 40 with BufferedReader

use of java.io.BufferedReader in project playn by threerings.

the class AndroidAssets method getTextSync.

@Override
public String getTextSync(String path) throws Exception {
    InputStream is = openAsset(path);
    try {
        StringBuilder fileData = new StringBuilder(1000);
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        char[] buf = new char[1024];
        int numRead = 0;
        while ((numRead = reader.read(buf)) != -1) {
            String readData = String.valueOf(buf, 0, numRead);
            fileData.append(readData);
        }
        reader.close();
        return fileData.toString();
    } finally {
        is.close();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader)

Aggregations

BufferedReader (java.io.BufferedReader)5525 InputStreamReader (java.io.InputStreamReader)3410 IOException (java.io.IOException)2592 FileReader (java.io.FileReader)1282 File (java.io.File)936 InputStream (java.io.InputStream)840 ArrayList (java.util.ArrayList)764 FileInputStream (java.io.FileInputStream)693 URL (java.net.URL)520 Test (org.junit.Test)446 FileNotFoundException (java.io.FileNotFoundException)379 StringReader (java.io.StringReader)340 BufferedWriter (java.io.BufferedWriter)242 HashMap (java.util.HashMap)232 HttpURLConnection (java.net.HttpURLConnection)227 Matcher (java.util.regex.Matcher)222 OutputStreamWriter (java.io.OutputStreamWriter)212 URLConnection (java.net.URLConnection)208 PrintWriter (java.io.PrintWriter)205 Reader (java.io.Reader)200