Search in sources :

Example 36 with FileReader

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;
}
Also used : ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File)

Example 37 with FileReader

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();
}
Also used : StringWriter(java.io.StringWriter) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) FileReader(java.io.FileReader)

Example 38 with FileReader

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);
}
Also used : FileWriter(java.io.FileWriter) FileReader(java.io.FileReader) File(java.io.File)

Example 39 with FileReader

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.
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) File(java.io.File)

Example 40 with FileReader

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);
    }
}
Also used : FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) FileInputStream(java.io.FileInputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ResultException(org.springsource.loaded.test.infra.ResultException) BufferedWriter(java.io.BufferedWriter)

Aggregations

FileReader (java.io.FileReader)1873 BufferedReader (java.io.BufferedReader)1289 IOException (java.io.IOException)893 File (java.io.File)811 FileNotFoundException (java.io.FileNotFoundException)304 ArrayList (java.util.ArrayList)274 Test (org.junit.Test)197 FileWriter (java.io.FileWriter)148 HashMap (java.util.HashMap)116 Reader (java.io.Reader)99 BufferedWriter (java.io.BufferedWriter)98 Properties (java.util.Properties)66 InputStreamReader (java.io.InputStreamReader)64 LineNumberReader (java.io.LineNumberReader)61 Matcher (java.util.regex.Matcher)61 Map (java.util.Map)59 List (java.util.List)56 PrintWriter (java.io.PrintWriter)51 StringTokenizer (java.util.StringTokenizer)51 HashSet (java.util.HashSet)50