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();
}
}
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));
}
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();
}
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);
}
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();
}
}
Aggregations