use of java.io.OutputStreamWriter 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.OutputStreamWriter 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.OutputStreamWriter 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.OutputStreamWriter in project weave by continuuity.
the class YarnWeavePreparer method saveLocalFiles.
/**
* Serializes the list of files that needs to localize from AM to Container.
*/
private void saveLocalFiles(Map<String, LocalFile> localFiles, Set<String> includes) throws IOException {
Map<String, LocalFile> localize = ImmutableMap.copyOf(Maps.filterKeys(localFiles, Predicates.in(includes)));
LOG.debug("Create and copy {}", Constants.Files.LOCALIZE_FILES);
Location location = createTempLocation(Constants.Files.LOCALIZE_FILES);
Writer writer = new OutputStreamWriter(location.getOutputStream(), Charsets.UTF_8);
try {
new GsonBuilder().registerTypeAdapter(LocalFile.class, new LocalFileCodec()).create().toJson(localize.values(), new TypeToken<List<LocalFile>>() {
}.getType(), writer);
} finally {
writer.close();
}
LOG.debug("Done {}", Constants.Files.LOCALIZE_FILES);
localFiles.put(Constants.Files.LOCALIZE_FILES, createLocalFile(Constants.Files.LOCALIZE_FILES, location));
}
use of java.io.OutputStreamWriter in project weave by continuuity.
the class YarnWeavePreparer method saveArguments.
private void saveArguments(Arguments arguments, Map<String, LocalFile> localFiles) throws IOException {
LOG.debug("Create and copy {}", Constants.Files.ARGUMENTS);
final Location location = createTempLocation(Constants.Files.ARGUMENTS);
ArgumentsCodec.encode(arguments, new OutputSupplier<Writer>() {
@Override
public Writer getOutput() throws IOException {
return new OutputStreamWriter(location.getOutputStream(), Charsets.UTF_8);
}
});
LOG.debug("Done {}", Constants.Files.ARGUMENTS);
localFiles.put(Constants.Files.ARGUMENTS, createLocalFile(Constants.Files.ARGUMENTS, location));
}
Aggregations