Search in sources :

Example 51 with FileWriter

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

the class OldFileWriterTest method test_ConstructorLjava_lang_String_IOException.

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

Example 52 with FileWriter

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

the class OldFileWriterTest method test_ConstructorLjava_io_File_IOException.

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

Example 53 with FileWriter

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

Example 54 with FileWriter

use of java.io.FileWriter in project CoreNLP by stanfordnlp.

the class DcorefSlowITest method makePropsFile.

protected void makePropsFile(String path, String workDir, String scorer) throws IOException {
    PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(path)));
    pw.println("annotators = pos, lemma, ner, parse");
    // WordNet is moved to more
    pw.println("dcoref.sievePasses = MarkRole, DiscourseMatch, ExactStringMatch, RelaxedExactStringMatch, PreciseConstructs, StrictHeadMatch1, StrictHeadMatch2, StrictHeadMatch3, StrictHeadMatch4, RelaxedHeadMatch, PronounMatch");
    // pw.println("dcoref.sievePasses = MarkRole, DiscourseMatch, ExactStringMatch, RelaxedExactStringMatch, PreciseConstructs, StrictHeadMatch1, StrictHeadMatch2, StrictHeadMatch3, StrictHeadMatch4, AliasMatch, RelaxedHeadMatch, LexicalChainMatch, PronounMatch");
    pw.println("dcoref.score = true");
    pw.println("dcoref.postprocessing = true");
    pw.println("dcoref.maxdist = -1");
    pw.println("dcoref.replicate.conll = true");
    pw.println("dcoref.conll.scorer = " + scorer);
    pw.println("dcoref.conll2011 = /scr/nlp/data/conll-2011/v2/data/dev/data/english/annotations");
    pw.println("dcoref.logFile = " + workDir + File.separator + "log.txt");
    pw.close();
}
Also used : FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 55 with FileWriter

use of java.io.FileWriter in project camel by apache.

the class RecordsUtil method createXMLFile.

public static void createXMLFile() {
    File in = new File("target/in/records.xml");
    if (in.exists()) {
        return;
    } else {
        if (!in.getParentFile().exists() && !in.getParentFile().mkdirs()) {
            throw new RuntimeException("can't create " + in.getParent());
        }
    }
    Records records = new Records();
    for (int i = 0; i < 10; i++) {
        Record record = new Record();
        record.setKey(Integer.toString(i));
        record.setValue("#" + i);
        records.getRecord().add(record);
    }
    Marshaller marshaller;
    try {
        JAXBContext jaxbCtx = JAXBContext.newInstance(Records.class.getPackage().getName());
        marshaller = jaxbCtx.createMarshaller();
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
    FileWriter writer = null;
    try {
        writer = new FileWriter(in);
        marshaller.marshal(records, writer);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    } finally {
        if (writer != null) {
            try {
                writer.flush();
                writer.close();
            } catch (IOException e) {
            // no-op
            }
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) FileWriter(java.io.FileWriter) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) 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