Search in sources :

Example 31 with AsyncFile

use of io.vertx.core.file.AsyncFile in project vertx-web by vert-x3.

the class InterceptorTest method testMutateCodecInterceptor.

@Test
public void testMutateCodecInterceptor() throws Exception {
    server.requestHandler(req -> req.response().end("foo!"));
    startServer();
    File f = Files.createTempFile("vertx", ".dat").toFile();
    assertTrue(f.delete());
    AsyncFile foo = vertx.fileSystem().openBlocking(f.getAbsolutePath(), new OpenOptions().setSync(true).setTruncateExisting(true));
    client.addInterceptor(this::handleMutateCodec);
    HttpRequest<Void> builder = client.get("/somepath").as(BodyCodec.pipe(foo));
    builder.send(onSuccess(resp -> {
        foo.write(Buffer.buffer("bar!"));
        foo.close(onSuccess(v -> {
            assertEquals("bar!", vertx.fileSystem().readFileBlocking(f.getAbsolutePath()).toString());
            testComplete();
        }));
    }));
    await();
    if (f.exists()) {
        f.delete();
    }
}
Also used : OpenOptions(io.vertx.core.file.OpenOptions) AsyncFile(io.vertx.core.file.AsyncFile) Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) MultiMap(io.vertx.core.MultiMap) BodyCodec(io.vertx.ext.web.codec.BodyCodec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) ClientPhase(io.vertx.ext.web.client.impl.ClientPhase) ArrayList(java.util.ArrayList) HttpTestBase(io.vertx.core.http.HttpTestBase) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpClientOptions(io.vertx.core.http.HttpClientOptions) RepeatRule(io.vertx.ext.unit.junit.RepeatRule) WebClientInternal(io.vertx.ext.web.client.impl.WebClientInternal) OpenOptions(io.vertx.core.file.OpenOptions) Files(java.nio.file.Files) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) File(java.io.File) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Handler(io.vertx.core.Handler) Collections(java.util.Collections) HttpContext(io.vertx.ext.web.client.impl.HttpContext) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AsyncFile(io.vertx.core.file.AsyncFile) AsyncFile(io.vertx.core.file.AsyncFile) File(java.io.File) Test(org.junit.Test)

Aggregations

AsyncFile (io.vertx.core.file.AsyncFile)31 OpenOptions (io.vertx.core.file.OpenOptions)26 Buffer (io.vertx.core.buffer.Buffer)19 Handler (io.vertx.core.Handler)10 Test (org.junit.Test)10 Vertx (io.vertx.core.Vertx)9 File (java.io.File)9 AsyncResult (io.vertx.core.AsyncResult)8 FileSystem (io.vertx.core.file.FileSystem)7 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Future (io.vertx.core.Future)6 JsonObject (io.vertx.core.json.JsonObject)6 WriteStream (io.vertx.core.streams.WriteStream)6 IOException (java.io.IOException)6 ReadStream (io.vertx.core.streams.ReadStream)5 FileNotFoundException (java.io.FileNotFoundException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 JsonArray (io.vertx.core.json.JsonArray)4 TestUtils (io.vertx.test.core.TestUtils)4