use of java.io.Writer in project cogtool by cogtool.
the class ProjectController method exportDesignToXML.
private boolean exportDesignToXML(Design design) {
String defaultFilename = ((design != null) ? design.getName() : project.getName()) + ".xml";
File exportFile = null;
if (interaction != null && CogTool.exportCSVKludgeDir == null) {
exportFile = interaction.selectXMLFile(false, defaultFilename);
} else {
exportFile = new File(CogTool.exportCSVKludgeDir, defaultFilename);
}
if (exportFile == null) {
return false;
}
OutputStream oStream = null;
String completionMsg;
try {
try {
oStream = new FileOutputStream(exportFile);
Writer xmlWriter = new BufferedWriter(new OutputStreamWriter(oStream, "UTF-8"));
if (design == null) {
ExportCogToolXML.exportXML(project, xmlWriter, "UTF-8");
completionMsg = allDesignsExportedToXml;
} else {
Map<ITaskDesign, TaskApplication> designTAs = project.taskApplicationsForDesign(design);
ExportCogToolXML.exportXML(design, designTAs, xmlWriter, "UTF-8");
completionMsg = designExportedToXml;
}
xmlWriter.flush();
} finally {
if (oStream != null) {
oStream.close();
}
}
} catch (IllegalArgumentException e) {
throw new RcvrIllegalStateException("Invalid argument exporting to XML", e);
} catch (IllegalStateException e) {
throw new RcvrIllegalStateException("Exporting to XML", e);
} catch (IOException e) {
throw new RcvrIOSaveException("Exporting to XML", e);
} catch (Exception e) {
throw new RecoverableException("Exporting to XML", e);
}
if (interaction != null) {
interaction.setStatusMessage(completionMsg + " " + exportFile.getAbsolutePath());
}
return true;
}
use of java.io.Writer in project cw-omnibus by commonsguy.
the class ScheduledService method append.
private void append(File f, RandomEvent event) {
try {
FileOutputStream fos = new FileOutputStream(f, true);
Writer osw = new OutputStreamWriter(fos);
osw.write(event.when.toString());
osw.write(" : ");
osw.write(Integer.toHexString(event.value));
osw.write('\n');
osw.flush();
fos.flush();
fos.getFD().sync();
fos.close();
Log.d(getClass().getSimpleName(), "logged to " + f.getAbsolutePath());
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Exception writing to file", e);
}
}
use of java.io.Writer in project cw-omnibus by commonsguy.
the class ScheduledService method append.
private void append(File f, RandomEvent event) {
try {
FileOutputStream fos = new FileOutputStream(f, true);
Writer osw = new OutputStreamWriter(fos);
osw.write(event.when.toString());
osw.write(" : ");
osw.write(Integer.toHexString(event.value));
osw.write('\n');
osw.flush();
fos.flush();
fos.getFD().sync();
fos.close();
Log.d(getClass().getSimpleName(), "logged to " + f.getAbsolutePath());
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Exception writing to file", e);
}
}
use of java.io.Writer in project cucumber-jvm by cucumber.
the class URLOutputStreamTest method write_to_file_without_existing_parent_directory.
@Test
public void write_to_file_without_existing_parent_directory() throws IOException, URISyntaxException {
Path filesWithoutParent = Files.createTempDirectory("filesWithoutParent");
String baseURL = filesWithoutParent.toUri().toURL().toString();
URL urlWithoutParentDirectory = new URL(baseURL + "/non/existing/directory");
Writer w = new UTF8OutputStreamWriter(new URLOutputStream(urlWithoutParentDirectory));
w.write("Hellesøy");
w.close();
File testFile = new File(urlWithoutParentDirectory.toURI());
assertEquals("Hellesøy", FixJava.readReader(openUTF8FileReader(testFile)));
}
use of java.io.Writer in project cucumber-jvm by cucumber.
the class URLOutputStreamTest method can_http_put.
@Test
public void can_http_put() throws IOException, ExecutionException, InterruptedException {
final BlockingQueue<String> data = new LinkedBlockingDeque<String>();
Rest r = new Rest(webbit);
r.PUT("/.cucumber/stepdefs.json", new HttpHandler() {
@Override
public void handleHttpRequest(HttpRequest req, HttpResponse res, HttpControl ctl) throws Exception {
data.offer(req.body());
res.end();
}
});
Writer w = new UTF8OutputStreamWriter(new URLOutputStream(new URL(Utils.toURL("http://localhost:9873/.cucumber"), "stepdefs.json")));
w.write("Hellesøy");
w.flush();
w.close();
assertEquals("Hellesøy", data.poll(1000, TimeUnit.MILLISECONDS));
}
Aggregations