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