Search in sources :

Example 46 with FileWriter

use of java.io.FileWriter in project iosched by google.

the class DiskLruCacheTest method openWithTruncatedLineDiscardsThatLine.

@Test
public void openWithTruncatedLineDiscardsThatLine() throws Exception {
    cache.close();
    writeFile(getCleanFile("k1", 0), "A");
    writeFile(getCleanFile("k1", 1), "B");
    Writer writer = new FileWriter(journalFile);
    // no trailing newline
    writer.write(MAGIC + "\n" + VERSION_1 + "\n100\n2\n\nCLEAN k1 1 1");
    writer.close();
    cache = DiskLruCache.open(cacheDir, appVersion, 2, Integer.MAX_VALUE);
    assertThat(cache.get("k1")).isNull();
}
Also used : FileWriter(java.io.FileWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 47 with FileWriter

use of java.io.FileWriter in project iosched by google.

the class DiskLruCacheTest method createJournalWithHeader.

private void createJournalWithHeader(String magic, String version, String appVersion, String valueCount, String blank, String... bodyLines) throws Exception {
    Writer writer = new FileWriter(journalFile);
    writer.write(magic + "\n");
    writer.write(version + "\n");
    writer.write(appVersion + "\n");
    writer.write(valueCount + "\n");
    writer.write(blank + "\n");
    for (String line : bodyLines) {
        writer.write(line);
        writer.write('\n');
    }
    writer.close();
}
Also used : FileWriter(java.io.FileWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 48 with FileWriter

use of java.io.FileWriter in project j2objc by google.

the class EnvironmentCheck method main.

/**
   * Command line runnability: checks for [-out outFilename] arg.
   * <p>Command line entrypoint; Sets output and calls 
   * {@link #checkEnvironment(PrintWriter)}.</p>
   * @param args command line args
   */
public static void main(String[] args) {
    // Default to System.out, autoflushing
    PrintWriter sendOutputTo = new PrintWriter(System.out, true);
    // Read our simplistic input args, if supplied
    for (int i = 0; i < args.length; i++) {
        if ("-out".equalsIgnoreCase(args[i])) {
            i++;
            if (i < args.length) {
                try {
                    sendOutputTo = new PrintWriter(new FileWriter(args[i], true));
                } catch (Exception e) {
                    System.err.println("# WARNING: -out " + args[i] + " threw " + e.toString());
                }
            } else {
                System.err.println("# WARNING: -out argument should have a filename, output sent to console");
            }
        }
    }
    EnvironmentCheck app = new EnvironmentCheck();
    app.checkEnvironment(sendOutputTo);
}
Also used : FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter)

Example 49 with FileWriter

use of java.io.FileWriter in project j2objc by google.

the class OldFileWriterTest method test_ConstructorLjava_io_FileZ_IOException.

public void test_ConstructorLjava_io_FileZ_IOException() {
    File dir = new File(System.getProperty("java.io.tmpdir"));
    try {
        fw = new FileWriter(dir, true);
        fail("Test 1: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 50 with FileWriter

use of java.io.FileWriter 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)

Aggregations

FileWriter (java.io.FileWriter)1994 File (java.io.File)1195 IOException (java.io.IOException)866 BufferedWriter (java.io.BufferedWriter)798 PrintWriter (java.io.PrintWriter)329 Test (org.junit.Test)243 Writer (java.io.Writer)181 FileReader (java.io.FileReader)148 BufferedReader (java.io.BufferedReader)128 ArrayList (java.util.ArrayList)121 FileNotFoundException (java.io.FileNotFoundException)78 Date (java.util.Date)68 FileOutputStream (java.io.FileOutputStream)65 Properties (java.util.Properties)65 HashMap (java.util.HashMap)61 FileInputStream (java.io.FileInputStream)54 StringWriter (java.io.StringWriter)51 Path (org.apache.hadoop.fs.Path)50 Map (java.util.Map)42 InputStreamReader (java.io.InputStreamReader)34