Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup committed Feb 21, 2017
1 parent 04ec098 commit 0d218d3
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ InetSocketAddress start() throws IOException {

executorService.submit(() -> {
try (RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw")) {
log.info("Created RandomAccessFile from " + file);
Future<Long> inputFuture = executorService.submit(() -> {
try (
InputStream in = incomingSocket.getInputStream();
FileOutputStream out = new FileOutputStream(randomAccessFile.getFD())
) {
return IOUtils.copyLarge(in, out);
} catch (Exception e) {
log.warn("", e);
return null;
}
});

Expand All @@ -103,11 +107,16 @@ InetSocketAddress start() throws IOException {
OutputStream out = incomingSocket.getOutputStream()
) {
return IOUtils.copyLarge(in, out);
} catch (Exception e) {
log.warn("", e);
return null;
}
});

inputFuture.get();
outputFuture.get();
} catch (Exception e) {
log.warn("", e);
} finally {
incomingSocket.close();
}
Expand All @@ -118,6 +127,8 @@ InetSocketAddress start() throws IOException {
log.warn("", e);
}
}
} catch (Exception e) {
log.warn("", e);
} finally {
listenSocket.close();
}
Expand Down

0 comments on commit 0d218d3

Please sign in to comment.