Examples of AsyncFile


Examples of io.vertx.core.file.AsyncFile

    assertNullPointerException(() -> vertx.fileSystem().existsSync(null));
    assertNullPointerException(() -> vertx.fileSystem().fsProps(null, h -> {}));
    assertNullPointerException(() -> vertx.fileSystem().fsPropsSync(null));

    String fileName = "some-file.dat";
    AsyncFile asyncFile = vertx.fileSystem().openSync(testDir + pathSep + fileName, new OpenOptions());

    assertNullPointerException(() -> asyncFile.write(null));
    assertIllegalArgumentException(() -> asyncFile.setWriteQueueMaxSize(1));
    assertIllegalArgumentException(() -> asyncFile.setWriteQueueMaxSize(0));
    assertIllegalArgumentException(() -> asyncFile.setWriteQueueMaxSize(-1));
    assertNullPointerException(() -> asyncFile.write(null, 0, h -> {}));
    assertNullPointerException(() -> asyncFile.write(Buffer.buffer(), 0, null));
    assertIllegalArgumentException(() -> asyncFile.write(Buffer.buffer(), -1, h -> {}));

    assertNullPointerException(() -> asyncFile.read(null, 0, 0, 0, h -> {}));
    assertNullPointerException(() -> asyncFile.read(Buffer.buffer(), 0, 0, 0, null));

    assertIllegalArgumentException(() -> asyncFile.read(Buffer.buffer(), -1, 0, 0, h -> {}));
    assertIllegalArgumentException(() -> asyncFile.read(Buffer.buffer(), 0, -1, 0, h -> {}));
    assertIllegalArgumentException(() -> asyncFile.read(Buffer.buffer(), 0, 0, -1, h -> {}));
  }
View Full Code Here

Examples of io.vertx.core.file.AsyncFile

    createFile(fileName, existing);
    byte[] content = TestUtils.randomByteArray(chunkSize * chunks);
    Buffer buff = Buffer.buffer(content);
    vertx.fileSystem().open(testDir + pathSep + fileName, new OpenOptions(), ar -> {
      if (ar.succeeded()) {
        AsyncFile ws = ar.result();
        long size = vertx.fileSystem().propsSync(testDir + pathSep + fileName).size();
        ws.setWritePos(size);
        ws.exceptionHandler(t -> fail(t.getMessage()));
        for (int i = 0; i < chunks; i++) {
          Buffer chunk = buff.getBuffer(i * chunkSize, (i + 1) * chunkSize);
          assertEquals(chunkSize, chunk.length());
          ws.write(chunk);
        }
        ar.result().close(ar2 -> {
          if (ar2.failed()) {
            fail(ar2.cause().getMessage());
          } else {
View Full Code Here

Examples of io.vertx.core.file.AsyncFile

    int chunks = 10;
    byte[] content = TestUtils.randomByteArray(chunkSize * chunks);
    createFile(fileName, content);
    vertx.fileSystem().open(testDir + pathSep + fileName, new OpenOptions(), ar -> {
      if (ar.succeeded()) {
        AsyncFile rs = ar.result();
        rs.setReadPos(chunkSize * chunks / 2);
        Buffer buff = Buffer.buffer();
        rs.handler(buff::appendBuffer);
        rs.exceptionHandler(t -> fail(t.getMessage()));
        rs.endHandler(v -> {
          ar.result().close(ar2 -> {
            if (ar2.failed()) {
              fail(ar2.cause().getMessage());
            } else {
              assertEquals(chunkSize * chunks / 2, buff.length());
View Full Code Here

Examples of io.vertx.core.file.AsyncFile

  @Test
  public void testAsyncFileCloseHandlerIsAsync() throws Exception {
    String fileName = "some-file.dat";
    createFileWithJunk(fileName, 100);
    AsyncFile file = vertx.fileSystem().openSync(testDir + pathSep + fileName, new OpenOptions());
    ThreadLocal stack = new ThreadLocal();
    stack.set(true);
    file.close(ar -> {
      assertNull(stack.get());
      assertTrue(vertx.context().isEventLoopContext());
      testComplete();
    });
    await();
View Full Code Here

Examples of org.vertx.java.core.file.AsyncFile

                  public void handle(AsyncResult<AsyncFile> result) {
                    if (result.failed()) {
                      new DefaultFutureResult<Void>(result.cause()).setHandler(doneHandler);
                    } else {
                      // Send a message to the node telling it we're going to upload the module.
                      final AsyncFile file = result.result();
                      JsonObject message = new JsonObject()
                          .putString("action", "upload");
                      vertx.eventBus().sendWithTimeout(address, message, DEFAULT_REPLY_TIMEOUT, new Handler<AsyncResult<Message<JsonObject>>>() {
                        @Override
                        public void handle(AsyncResult<Message<JsonObject>> result) {
View Full Code Here

Examples of org.vertx.java.core.file.AsyncFile

          public void handle(AsyncResult<AsyncFile> ar) {
            if (ar.failed()) {
              ar.cause().printStackTrace();
              return;
            }
            final AsyncFile file = ar.result();
            final Pump pump = Pump.createPump(req, file);
            final long start = System.currentTimeMillis();
            req.endHandler(new VoidHandler() {
              public void handle() {
                file.close(new AsyncResultHandler<Void>() {
                  public void handle(AsyncResult<Void> ar) {
                    if (ar.succeeded()) {
                      req.response().end();
                      long end = System.currentTimeMillis();
                      System.out.println("Uploaded " + pump.bytesPumped() + " bytes to " + filename + " in " + (end - start) + " ms");
View Full Code Here

Examples of org.vertx.java.core.file.AsyncFile

      // For a chunked upload you don't need to specify size, just do:
      // req.setChunked(true);

      vertx.fileSystem().open(filename, new AsyncResultHandler<AsyncFile>() {
        public void handle(AsyncResult<AsyncFile> ar) {
          final AsyncFile file = ar.result();
          Pump pump = Pump.createPump(file, req);
          pump.start();

          file.endHandler(new VoidHandler() {
            public void handle() {

              file.close(new AsyncResultHandler<Void>() {
                public void handle(AsyncResult<Void> ar) {
                  if (ar.succeeded()) {
                    req.end();
                    System.out.println("Sent request");
                  } else {
View Full Code Here

Examples of org.vertx.java.core.file.AsyncFile

        final String filename = "upload/file-" + UUID.randomUUID().toString() + ".upload";

        vertx.fileSystem().open(filename, new AsyncResultHandler<AsyncFile>() {
          public void handle(AsyncResult<AsyncFile> ar) {
            final AsyncFile file = ar.result;
            final Pump pump = Pump.createPump(req, file.getWriteStream());
            final long start = System.currentTimeMillis();
            req.endHandler(new SimpleHandler() {
              public void handle() {
                file.close(new AsyncResultHandler<Void>() {
                  public void handle(AsyncResult<Void> ar) {
                    if (ar.exception == null) {
                      req.response.end();
                      long end = System.currentTimeMillis();
                      System.out.println("Uploaded " + pump.getBytesPumped() + " bytes to " + filename + " in " + (end - start) + " ms");
View Full Code Here

Examples of org.vertx.java.core.file.AsyncFile

    // For a chunked upload you don't need to specify size, just do:
    // req.setChunked(true);

    vertx.fileSystem().open(filename, new AsyncResultHandler<AsyncFile>() {
      public void handle(AsyncResult<AsyncFile> ar) {
        final AsyncFile file = ar.result;
        Pump pump = Pump.createPump(file.getReadStream(), req);
        pump.start();

        file.getReadStream().endHandler(new SimpleHandler() {
          public void handle() {

            file.close(new AsyncResultHandler<Void>() {
              public void handle(AsyncResult<Void> ar) {
                if (ar.exception == null) {
                  req.end();
                  System.out.println("Sent request");
                } else {
View Full Code Here

Examples of org.vertx.java.core.file.AsyncFile

        final String filename = "upload/file-" + UUID.randomUUID().toString() + ".upload";

        vertx.fileSystem().open(filename, new AsyncResultHandler<AsyncFile>() {
          public void handle(AsyncResult<AsyncFile> ar) {
            final AsyncFile file = ar.result;
            final Pump pump = Pump.createPump(req, file.getWriteStream());
            final long start = System.currentTimeMillis();
            req.endHandler(new SimpleHandler() {
              public void handle() {
                file.close(new AsyncResultHandler<Void>() {
                  public void handle(AsyncResult<Void> ar) {
                    if (ar.exception == null) {
                      req.response.end();
                      long end = System.currentTimeMillis();
                      System.out.println("Uploaded " + pump.getBytesPumped() + " bytes to " + filename + " in " + (end - start) + " ms");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.