Skip to content

Commit

Permalink
create and open file in one step rather than two
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Oct 29, 2021
1 parent 321d422 commit 3cd1f37
Showing 1 changed file with 22 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,49 +192,32 @@ public void handle(RoutingContext ctx) {
});
ctx.vertx()
.fileSystem()
.createFile(
.open(
destinationFile,
createFile -> {
if (createFile.failed()) {
ctx.fail(new HttpStatusException(500, createFile.cause()));
new OpenOptions().setAppend(true).setCreateNew(true),
openFile -> {
if (openFile.failed()) {
ctx.fail(new HttpStatusException(500, openFile.cause()));
return;
}
ctx.vertx()
.fileSystem()
.open(
destinationFile,
new OpenOptions().setAppend(true),
openFile -> {
if (openFile.failed()) {
ctx.fail(
new HttpStatusException(
500, openFile.cause()));
return;
}
ctx.request()
.handler(
buffer -> {
lastReadTimestamp.set(
System.nanoTime());
openFile.result().write(buffer);
})
.exceptionHandler(
fileUploadPath
::completeExceptionally)
.endHandler(
v -> {
ctx.vertx()
.cancelTimer(timerId);
openFile.result().close();
fileUploadPath.complete(
destinationFile);
});
ctx.addEndHandler(
ar -> {
ctx.vertx().cancelTimer(timerId);
});
ctx.request().resume();
ctx.request()
.handler(
buffer -> {
lastReadTimestamp.set(System.nanoTime());
openFile.result().write(buffer);
})
.exceptionHandler(fileUploadPath::completeExceptionally)
.endHandler(
v -> {
ctx.vertx().cancelTimer(timerId);
openFile.result().close();
fileUploadPath.complete(destinationFile);
});
ctx.addEndHandler(
ar -> {
ctx.vertx().cancelTimer(timerId);
});
ctx.request().resume();
});

try {
Expand Down

0 comments on commit 3cd1f37

Please sign in to comment.