use of io.vertx.core.Vertx in project vert.x by eclipse.
the class StreamsExamples method pump2.
public void pump2(Vertx vertx) {
NetServer server = vertx.createNetServer(new NetServerOptions().setPort(1234).setHost("localhost"));
server.connectHandler(sock -> {
sock.handler(buffer -> {
if (!sock.writeQueueFull()) {
sock.write(buffer);
}
});
}).listen();
}
use of io.vertx.core.Vertx in project vert.x by eclipse.
the class StreamsExamples method pump1.
public void pump1(Vertx vertx) {
NetServer server = vertx.createNetServer(new NetServerOptions().setPort(1234).setHost("localhost"));
server.connectHandler(sock -> {
sock.handler(buffer -> {
sock.write(buffer);
});
}).listen();
}
use of io.vertx.core.Vertx in project vert.x by eclipse.
the class FileSystemExamples method asyncFileWrite.
public void asyncFileWrite() {
Vertx vertx = Vertx.vertx();
vertx.fileSystem().open("target/classes/hello.txt", new OpenOptions(), result -> {
if (result.succeeded()) {
AsyncFile file = result.result();
Buffer buff = Buffer.buffer("foo");
for (int i = 0; i < 5; i++) {
file.write(buff, buff.length() * i, ar -> {
if (ar.succeeded()) {
System.out.println("Written ok!");
} else {
System.err.println("Failed to write: " + ar.cause());
}
});
}
} else {
System.err.println("Cannot open file " + result.cause());
}
});
}
use of io.vertx.core.Vertx in project vert.x by eclipse.
the class FileSystemExamples method asyncAPIExamples.
public void asyncAPIExamples() {
Vertx vertx = Vertx.vertx();
// Read a file
vertx.fileSystem().readFile("target/classes/readme.txt", result -> {
if (result.succeeded()) {
System.out.println(result.result());
} else {
System.err.println("Oh oh ..." + result.cause());
}
});
// Copy a file
vertx.fileSystem().copy("target/classes/readme.txt", "target/classes/readme2.txt", result -> {
if (result.succeeded()) {
System.out.println("File copied");
} else {
System.err.println("Oh oh ..." + result.cause());
}
});
// Write a file
vertx.fileSystem().writeFile("target/classes/hello.txt", Buffer.buffer("Hello"), result -> {
if (result.succeeded()) {
System.out.println("File written");
} else {
System.err.println("Oh oh ..." + result.cause());
}
});
// Check existence and delete
vertx.fileSystem().exists("target/classes/junk.txt", result -> {
if (result.succeeded() && result.result()) {
vertx.fileSystem().delete("target/classes/junk.txt", r -> {
System.out.println("File deleted");
});
} else {
System.err.println("Oh oh ... - cannot delete the file: " + result.cause());
}
});
}
use of io.vertx.core.Vertx in project vert.x by eclipse.
the class FileResolverTestBase method testCacheDirDeletedOnVertxClose.
@Test
public void testCacheDirDeletedOnVertxClose() {
VertxInternal vertx2 = (VertxInternal) vertx();
File file = vertx2.resolveFile(webRoot + "/somefile.html");
assertTrue(file.exists());
File cacheDir = file.getParentFile().getParentFile();
assertTrue(cacheDir.exists());
vertx2.close(onSuccess(v -> {
assertFalse(cacheDir.exists());
testComplete();
}));
await();
}
Aggregations