use of io.vertx.core.file.FileSystem in project vertx-openshift-it by cescoffier.
the class StreamingResultsTest method handle.
@Override
public void handle(RoutingContext rc) {
jdbcClient.getConnection(ar -> {
if (ar.failed()) {
fail(rc, ar.cause());
return;
}
SQLConnection connection = ar.result();
rc.response().bodyEndHandler(v -> {
connection.close();
});
FileSystem fileSystem = rc.vertx().fileSystem();
fileSystem.open("db/migration/strings", new OpenOptions(), ores -> {
if (ores.failed()) {
fail(rc, ores.cause());
return;
}
AsyncFile asyncFile = ores.result();
List<String> values = new ArrayList<>();
RecordParser parser = RecordParser.newDelimited("\n", out -> values.add(out.toString()));
asyncFile.handler(parser);
asyncFile.endHandler(v -> {
asyncFile.close();
List<String> statements = values.stream().map(value -> "insert into random_string (value) values ('" + value + "')").collect(toList());
connection.batch(statements, ires -> {
if (ires.failed()) {
fail(rc, ires.cause());
return;
}
connection.queryStream("select value from random_string", sres -> {
if (sres.failed()) {
fail(rc, sres.cause());
return;
}
List<String> storedValues = new ArrayList<>(values.size());
SQLRowStream rowStream = sres.result();
rowStream.handler(row -> {
storedValues.add(row.getString(0));
}).endHandler(endRows -> {
if (!storedValues.equals(values)) {
fail(rc, storedValues.toString());
} else {
rc.response().setStatusCode(200).end();
}
});
});
});
});
});
});
}
use of io.vertx.core.file.FileSystem in project vert.x by eclipse.
the class HttpServerFileUploadImpl method streamToFileSystem.
@Override
public Future<Void> streamToFileSystem(String filename) {
synchronized (this) {
if (pipe != null) {
return context.failedFuture("Already streaming");
}
pipe = pipe().endOnComplete(true);
}
FileSystem fs = context.owner().fileSystem();
Future<AsyncFile> fut = fs.open(filename, new OpenOptions());
fut.onFailure(err -> {
pipe.close();
});
return fut.compose(f -> {
Future<Void> to = pipe.to(f);
return to.compose(v -> {
synchronized (HttpServerFileUploadImpl.this) {
if (!cancelled) {
file = f;
return context.succeededFuture();
}
fs.delete(filename);
return context.failedFuture("Streaming aborted");
}
}, err -> {
fs.delete(filename);
return context.failedFuture(err);
});
});
}
use of io.vertx.core.file.FileSystem in project vert.x by eclipse.
the class CoreExamples method exampleFuture2.
public void exampleFuture2(Vertx vertx, Handler<HttpServerRequest> requestHandler) {
FileSystem fs = vertx.fileSystem();
Future<FileProps> future = fs.props("/my_file.txt");
future.onComplete((AsyncResult<FileProps> ar) -> {
if (ar.succeeded()) {
FileProps props = ar.result();
System.out.println("File size = " + props.size());
} else {
System.out.println("Failure: " + ar.cause().getMessage());
}
});
}
use of io.vertx.core.file.FileSystem in project azure-iot-sdk-java by Azure.
the class MainApiVerticle method start.
@SuppressWarnings("deprecation")
@Override
public void start(Future<Void> startFuture) throws Exception {
Json.mapper.registerModule(new JavaTimeModule());
FileSystem vertxFileSystem = vertx.fileSystem();
vertxFileSystem.readFile("swagger.json", readFile -> {
if (readFile.succeeded()) {
Swagger swagger = new SwaggerParser().parse(readFile.result().toString(StandardCharsets.UTF_8));
Router swaggerRouter = SwaggerRouter.swaggerRouter(router, swagger, vertx.eventBus(), new OperationIdServiceIdResolver(), t -> new DeliveryOptions().setSendTimeout(90000));
deployVerticles(startFuture);
vertx.createHttpServer().requestHandler(swaggerRouter::accept).listen(8080);
startFuture.complete();
} else {
startFuture.fail(readFile.cause());
}
});
}
use of io.vertx.core.file.FileSystem in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
HttpClientRequest req = vertx.createHttpClient(new HttpClientOptions()).put(8080, "localhost", "/someurl", resp -> {
System.out.println("Response " + resp.statusCode());
});
String filename = "upload.txt";
FileSystem fs = vertx.fileSystem();
fs.props(filename, ares -> {
FileProps props = ares.result();
System.out.println("props is " + props);
long size = props.size();
req.headers().set("content-length", "" + size);
fs.open(filename, new OpenOptions(), ares2 -> {
AsyncFile file = ares2.result();
Pump pump = Pump.pump(file, req);
file.endHandler(v -> {
req.end();
});
pump.start();
});
});
}
Aggregations