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);
}
}
use of java.io.OutputStreamWriter in project checkstyle by checkstyle.
the class XMLLogger method setOutputStream.
/**
* Sets the OutputStream.
* @param outputStream the OutputStream to use
**/
private void setOutputStream(OutputStream outputStream) {
final OutputStreamWriter osw = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
writer = new PrintWriter(osw);
}
Aggregations