Skip to content

Commit

Permalink
#291 more cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup committed Feb 21, 2017
1 parent c819aba commit 6c5d14e
Showing 1 changed file with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class NamedPipeSocketClientProviderStrategy extends DockerClientProviderStrategy {

Expand Down Expand Up @@ -85,23 +86,30 @@ InetSocketAddress start() throws IOException {
Socket incomingSocket = listenSocket.accept();
log.debug("Accepting incoming connection from {}", incomingSocket.getRemoteSocketAddress());

RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");

executorService.submit(() -> {
try (
InputStream in = incomingSocket.getInputStream();
FileOutputStream out = new FileOutputStream(randomAccessFile.getFD())
) {
return IOUtils.copyLarge(in, out);
}
});
executorService.submit(() -> {
try (
FileInputStream in = new FileInputStream(randomAccessFile.getFD());
OutputStream out = incomingSocket.getOutputStream()
) {
return IOUtils.copyLarge(in, out);
try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw")) {
Future<Long> inputFuture = executorService.submit(() -> {
try (
InputStream in = incomingSocket.getInputStream();
FileOutputStream out = new FileOutputStream(randomAccessFile.getFD())
) {
return IOUtils.copyLarge(in, out);
}
});

Future<Long> outputFuture = executorService.submit(() -> {
try (
FileInputStream in = new FileInputStream(randomAccessFile.getFD());
OutputStream out = incomingSocket.getOutputStream()
) {
return IOUtils.copyLarge(in, out);
}
});

inputFuture.get();
outputFuture.get();
}
return null;
});

} catch (IOException e) {
Expand Down

0 comments on commit 6c5d14e

Please sign in to comment.