use of java.io.FileReader in project JavaVersionChanger by guigarage.
the class LaunchdConfig method readCompleteLaunchdFile.
private List<String> readCompleteLaunchdFile() throws IOException, InterruptedException {
changePermissionToWriteable();
List<String> lines = new ArrayList<String>();
File launchdFile = new File(LAUNCHD_PATH);
FileReader reader = new FileReader(launchdFile);
BufferedReader bufferedReader = new BufferedReader(reader);
try {
while (bufferedReader.ready()) {
lines.add(bufferedReader.readLine());
}
} finally {
bufferedReader.close();
}
return lines;
}
use of java.io.FileReader in project iosched by google.
the class DiskLruCacheTest method readFile.
private static String readFile(File file) throws Exception {
Reader reader = new FileReader(file);
StringWriter writer = new StringWriter();
char[] buffer = new char[1024];
int count;
while ((count = reader.read(buffer)) != -1) {
writer.write(buffer, 0, count);
}
reader.close();
return writer.toString();
}
use of java.io.FileReader in project j2objc by google.
the class OldFileWriterTest method test_handleEarlyEOFChar_2.
public void test_handleEarlyEOFChar_2() throws IOException {
int capacity = 65536;
byte[] bytes = new byte[capacity];
byte[] bs = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
for (int i = 0; i < bytes.length; i++) {
bytes[i] = bs[i / 8192];
}
String inputStr = new String(bytes);
int len = inputStr.length();
File f = File.createTempFile("FileWriterBugTest ", null);
FileWriter writer = new FileWriter(f);
writer.write(inputStr);
writer.close();
long flen = f.length();
FileReader reader = new FileReader(f);
char[] outChars = new char[capacity];
int outCount = reader.read(outChars);
String outStr = new String(outChars, 0, outCount);
f.deleteOnExit();
assertEquals(len, flen);
assertEquals(inputStr, outStr);
}
use of java.io.FileReader in project j2objc by google.
the class OldFileReaderTest method test_ConstructorLjava_io_File.
public void test_ConstructorLjava_io_File() {
File noFile = new File(System.getProperty("java.io.tmpdir"), "noreader.tst");
try {
br = new FileReader(noFile);
fail("Test 2: FileNotFoundException expected.");
} catch (FileNotFoundException e) {
// Expected.
}
}
use of java.io.FileReader in project spring-loaded by spring-projects.
the class SpringLoadedTests method checkIt.
/**
* Look for a <name>.print file and check the printout of the bytes matches it, unless regenerate is true in which
* case the print out is recorded in that file.
*/
protected void checkIt(String name, byte[] bytes, boolean regenerate) {
String filename = "src/test/java/" + name.replace('.', '/') + ".print";
try {
if (regenerate) {
// create the file
System.out.println("creating " + filename);
File f = new File(filename);
FileWriter fos = new FileWriter(f);
BufferedWriter dos = new BufferedWriter(fos);
dos.write(printItAndReturnIt(bytes));
dos.flush();
fos.close();
} else {
// compare the files
List<String> expectedLines = new ArrayList<String>();
File f = new File(filename);
if (!f.exists()) {
Assert.fail("Must run with renegerate on once to create the expected output for '" + name + "'");
}
FileInputStream fis = new FileInputStream(f);
BufferedReader dis = new BufferedReader(new FileReader(new File(filename)));
String line = null;
while ((line = dis.readLine()) != null) {
if (line.length() != 0) {
expectedLines.add(line);
}
}
dis.close();
fis.close();
List<String> actualLines = toLines(printItAndReturnIt(bytes));
if (actualLines.size() != expectedLines.size()) {
System.out.println("actual lines=" + actualLines.size());
System.out.println(" exp lines=" + expectedLines.size());
Assert.assertEquals(expectedLines, actualLines);
}
for (int ln = 0; ln < expectedLines.size(); ln++) {
if (!expectedLines.get(ln).equals(actualLines.get(ln))) {
String expLine = (ln + 1) + " " + expectedLines.get(ln);
String actLine = (ln + 1) + " " + actualLines.get(ln);
Assert.assertEquals(expLine, actLine);
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations