use of java.io.OutputStreamWriter in project weave by continuuity.
the class YarnWeavePreparer method saveWeaveSpec.
private void saveWeaveSpec(WeaveSpecification spec, final Multimap<String, LocalFile> runnableLocalFiles, Map<String, LocalFile> localFiles) throws IOException {
// Rewrite LocalFiles inside weaveSpec
Map<String, RuntimeSpecification> runtimeSpec = Maps.transformEntries(spec.getRunnables(), new Maps.EntryTransformer<String, RuntimeSpecification, RuntimeSpecification>() {
@Override
public RuntimeSpecification transformEntry(String key, RuntimeSpecification value) {
return new DefaultRuntimeSpecification(value.getName(), value.getRunnableSpecification(), value.getResourceSpecification(), runnableLocalFiles.get(key));
}
});
// Serialize into a local temp file.
LOG.debug("Create and copy {}", Constants.Files.WEAVE_SPEC);
Location location = createTempLocation(Constants.Files.WEAVE_SPEC);
Writer writer = new OutputStreamWriter(location.getOutputStream(), Charsets.UTF_8);
try {
EventHandlerSpecification eventHandler = spec.getEventHandler();
if (eventHandler == null) {
eventHandler = new LogOnlyEventHandler().configure();
}
WeaveSpecificationAdapter.create().toJson(new DefaultWeaveSpecification(spec.getName(), runtimeSpec, spec.getOrders(), eventHandler), writer);
} finally {
writer.close();
}
LOG.debug("Done {}", Constants.Files.WEAVE_SPEC);
localFiles.put(Constants.Files.WEAVE_SPEC, createLocalFile(Constants.Files.WEAVE_SPEC, location));
}
use of java.io.OutputStreamWriter in project weave by continuuity.
the class FailureRestartTestRun method getInstances.
private Set<Integer> getInstances(Iterable<Discoverable> discoverables) throws IOException {
Set<Integer> instances = Sets.newHashSet();
for (Discoverable discoverable : discoverables) {
InetSocketAddress socketAddress = discoverable.getSocketAddress();
Socket socket = new Socket(socketAddress.getAddress(), socketAddress.getPort());
try {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true);
LineReader reader = new LineReader(new InputStreamReader(socket.getInputStream(), Charsets.UTF_8));
String msg = "Failure";
writer.println(msg);
String line = reader.readLine();
Assert.assertTrue(line.endsWith(msg));
instances.add(Integer.parseInt(line.substring(0, line.length() - msg.length())));
} finally {
socket.close();
}
}
return instances;
}
use of java.io.OutputStreamWriter in project weave by continuuity.
the class LocalFileTestRun method testLocalFile.
@Test
public void testLocalFile() throws Exception {
String header = Files.readFirstLine(new File(getClass().getClassLoader().getResource("header.txt").toURI()), Charsets.UTF_8);
WeaveRunner runner = YarnTestSuite.getWeaveRunner();
if (runner instanceof YarnWeaveRunnerService) {
((YarnWeaveRunnerService) runner).setJVMOptions("-verbose:gc -Xloggc:gc.log -XX:+PrintGCDetails");
}
WeaveController controller = runner.prepare(new LocalFileApplication()).withApplicationArguments("local").withArguments("LocalFileSocketServer", "local2").addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))).start();
if (runner instanceof YarnWeaveRunnerService) {
((YarnWeaveRunnerService) runner).setJVMOptions("");
}
Iterable<Discoverable> discoverables = controller.discoverService("local");
Assert.assertTrue(YarnTestSuite.waitForSize(discoverables, 1, 60));
InetSocketAddress socketAddress = discoverables.iterator().next().getSocketAddress();
Socket socket = new Socket(socketAddress.getAddress(), socketAddress.getPort());
try {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true);
LineReader reader = new LineReader(new InputStreamReader(socket.getInputStream(), Charsets.UTF_8));
String msg = "Local file test";
writer.println(msg);
Assert.assertEquals(header, reader.readLine());
Assert.assertEquals(msg, reader.readLine());
} finally {
socket.close();
}
controller.stopAndWait();
Assert.assertTrue(YarnTestSuite.waitForSize(discoverables, 0, 60));
TimeUnit.SECONDS.sleep(2);
}
use of java.io.OutputStreamWriter in project weave by continuuity.
the class SocketServer method run.
@Override
public void run() {
try {
runThread = Thread.currentThread();
while (running) {
try {
Socket socket = serverSocket.accept();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), Charsets.UTF_8));
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
handleRequest(reader, writer);
} finally {
socket.close();
}
} catch (SocketException e) {
LOG.info("Socket exception: " + e);
}
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
use of java.io.OutputStreamWriter in project cryptomator by cryptomator.
the class SettingsProvider method save.
private void save(Settings settings) {
assert settings != null : "method should only be invoked by #scheduleSave, which checks for null";
final Path settingsPath = getSettingsPath();
try {
Files.createDirectories(settingsPath.getParent());
try (//
OutputStream out = Files.newOutputStream(settingsPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) {
gson.toJson(settings, writer);
LOG.info("Settings saved to " + settingsPath);
}
} catch (IOException e) {
LOG.error("Failed to save settings.", e);
}
}
Aggregations