use of io.vertx.core.file.FileSystem in project vert.x by eclipse.
the class CoreExamples method exampleFuture1.
public void exampleFuture1(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 vert.x by eclipse.
the class FileSystemExamples method example1.
public void example1(Vertx vertx) {
FileSystem fs = vertx.fileSystem();
// Copy file from foo.txt to bar.txt
fs.copy("foo.txt", "bar.txt", res -> {
if (res.succeeded()) {
// Copied ok!
} else {
// Something went wrong
}
});
}
use of io.vertx.core.file.FileSystem in project vert.x by eclipse.
the class FileSystemExamples method example2.
public void example2(Vertx vertx) {
FileSystem fs = vertx.fileSystem();
// Copy file from foo.txt to bar.txt synchronously
fs.copyBlocking("foo.txt", "bar.txt");
}
use of io.vertx.core.file.FileSystem in project vert.x by eclipse.
the class HttpUtils method resolveFile.
static void resolveFile(VertxInternal vertx, String filename, long offset, long length, Handler<AsyncResult<AsyncFile>> resultHandler) {
File file_ = vertx.resolveFile(filename);
if (!file_.exists()) {
resultHandler.handle(Future.failedFuture(new FileNotFoundException()));
return;
}
// i.e is not a directory
try (RandomAccessFile raf = new RandomAccessFile(file_, "r")) {
FileSystem fs = vertx.fileSystem();
fs.open(filename, new OpenOptions().setCreate(false).setWrite(false), ar -> {
if (ar.succeeded()) {
AsyncFile file = ar.result();
long contentLength = Math.min(length, file_.length() - offset);
file.setReadPos(offset);
file.setReadLength(contentLength);
}
resultHandler.handle(ar);
});
} catch (IOException e) {
resultHandler.handle(Future.failedFuture(e));
}
}
use of io.vertx.core.file.FileSystem in project VX-API-Gateway by EliMirren.
the class VxApiClientJsonAuth method auth.
/**
* 验证用户是否有权限
*
* @param user
* @param vertx
* @param handler
*/
public static void auth(JsonObject authInfo, Vertx vertx, Handler<AsyncResult<Boolean>> handler) {
String username = authInfo.getString(VxApiRolesConstant.USER_NAME_KEY);
if (username == null) {
handler.handle(Future.succeededFuture(false));
} else {
String pwd = authInfo.getString(VxApiRolesConstant.USER_PWD_KEY);
String role = authInfo.getString(VxApiRolesConstant.USER_ROLE_KEY);
FileSystem file = vertx.fileSystem();
String path = PathUtil.getPathString("user.json");
file.readFile(path, res -> {
if (res.succeeded()) {
JsonObject users = res.result().toJsonObject();
if (users.getValue(username) instanceof JsonObject) {
JsonObject user = users.getJsonObject(username);
if (pwd != null && pwd.equals(user.getString("pwd")) && user.getJsonArray("roles").contains(role)) {
handler.handle(Future.<Boolean>succeededFuture(true));
} else {
handler.handle(Future.<Boolean>succeededFuture(false));
}
} else {
handler.handle(Future.<Boolean>succeededFuture(false));
}
} else {
handler.handle(Future.failedFuture(res.cause()));
}
});
}
}
Aggregations