io.vertx.core.file.FileSystem Java Examples

The following examples show how to use io.vertx.core.file.FileSystem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BodyHandlerImpl.java    From vertx-web with Apache License 2.0 8 votes vote down vote up
private void deleteFileUploads() {
  if (cleanup.compareAndSet(false, true) && handleFileUploads) {
    for (FileUpload fileUpload : context.fileUploads()) {
      FileSystem fileSystem = context.vertx().fileSystem();
      String uploadedFileName = fileUpload.uploadedFileName();
      fileSystem.exists(uploadedFileName, existResult -> {
        if (existResult.failed()) {
          log.warn("Could not detect if uploaded file exists, not deleting: " + uploadedFileName, existResult.cause());
        } else if (existResult.result()) {
          fileSystem.delete(uploadedFileName, deleteResult -> {
            if (deleteResult.failed()) {
              log.warn("Delete of uploaded file failed: " + uploadedFileName, deleteResult.cause());
            }
          });
        }
      });
    }
  }
}
 
Example #2
Source File: MainApiVerticle.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Override
public void start(Future<Void> startFuture) throws Exception {
    Json.mapper.registerModule(new JavaTimeModule());
    FileSystem vertxFileSystem = vertx.fileSystem();
    vertxFileSystem.readFile("openapi.json", readFile -> {
        if (readFile.succeeded()) {
            Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8")));
            Router swaggerRouter = SwaggerRouter.swaggerRouter(router, swagger, vertx.eventBus(), new OperationIdServiceIdResolver());

            deployVerticles(startFuture);

            vertx.createHttpServer()
                .requestHandler(swaggerRouter::accept) 
                .listen(serverPort, h -> {
                    if (h.succeeded()) {
                        startFuture.complete();
                    } else {
                        startFuture.fail(h.cause());
                    }
                });
        } else {
        	startFuture.fail(readFile.cause());
        }
    });        		        
}
 
Example #3
Source File: MainApiVerticle.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Override
public void start(Future<Void> startFuture) throws Exception {
    Json.mapper.registerModule(new JavaTimeModule());
    FileSystem vertxFileSystem = vertx.fileSystem();
    vertxFileSystem.readFile("openapi.json", readFile -> {
        if (readFile.succeeded()) {
            Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8")));
            Router swaggerRouter = SwaggerRouter.swaggerRouter(router, swagger, vertx.eventBus(), new OperationIdServiceIdResolver());

            deployVerticles(startFuture);

            vertx.createHttpServer()
                .requestHandler(swaggerRouter::accept) 
                .listen(serverPort, h -> {
                    if (h.succeeded()) {
                        startFuture.complete();
                    } else {
                        startFuture.fail(h.cause());
                    }
                });
        } else {
        	startFuture.fail(readFile.cause());
        }
    });        		        
}
 
Example #4
Source File: FileApplicationSettings.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
public FileApplicationSettings(FileSystem fileSystem, String settingsFileName, String storedRequestsDir,
                               String storedImpsDir, String storedResponsesDir) {

    final SettingsFile settingsFile = readSettingsFile(Objects.requireNonNull(fileSystem),
            Objects.requireNonNull(settingsFileName));

    accounts = toMap(settingsFile.getAccounts(),
            Account::getId,
            Function.identity());

    configs = toMap(settingsFile.getConfigs(),
            AdUnitConfig::getId,
            config -> ObjectUtils.defaultIfNull(config.getConfig(), StringUtils.EMPTY));

    this.storedIdToRequest = readStoredData(fileSystem, Objects.requireNonNull(storedRequestsDir));
    this.storedIdToImp = readStoredData(fileSystem, Objects.requireNonNull(storedImpsDir));
    this.storedIdToSeatBid = readStoredData(fileSystem, Objects.requireNonNull(storedResponsesDir));
}
 
Example #5
Source File: VertxVaadinService.java    From vertx-vaadin with MIT License 6 votes vote down vote up
public InputStream tryGetResourceAsStream(String path) {
    logger.trace("Try to resolve path {}", path);
    String relativePath = makePathRelative(path);
    FileSystem fileSystem = getVertx().fileSystem();
    if (fileSystem.existsBlocking(relativePath)) {
        return new BufferInputStreamAdapter(fileSystem.readFileBlocking(relativePath));
    }
    if (!path.startsWith("/META-INF/resources")) {
        logger.trace("Path {} not found, try into /META-INF/resources/", path);
        InputStream is = tryGetResourceAsStream("/META-INF/resources/" + relativePath);
        if (is != null) {
            return is;
        }
    }
    logger.trace("Path {} not found into META-INF/resources/, try with webjars");
    return vertxVaadin.webJars.getWebJarResourcePath(path)
        .filter(fileSystem::existsBlocking)
        .map(fileSystem::readFileBlocking)
        .map(BufferInputStreamAdapter::new)
        .orElse(null);
}
 
Example #6
Source File: RemoteFileSyncer.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
public static RemoteFileSyncer create(String downloadUrl, String saveFilePath, String tmpFilePath, int retryCount,
                                      long retryInterval, long timeout, long updatePeriod, HttpClient httpClient,
                                      Vertx vertx, FileSystem fileSystem) {
    HttpUtil.validateUrl(downloadUrl);
    Objects.requireNonNull(saveFilePath);
    Objects.requireNonNull(tmpFilePath);
    Objects.requireNonNull(vertx);
    Objects.requireNonNull(httpClient);
    Objects.requireNonNull(fileSystem);

    createAndCheckWritePermissionsFor(fileSystem, saveFilePath);
    createAndCheckWritePermissionsFor(fileSystem, tmpFilePath);

    return new RemoteFileSyncer(downloadUrl, saveFilePath, tmpFilePath, retryCount, retryInterval, timeout,
            updatePeriod, httpClient, vertx, fileSystem);
}
 
Example #7
Source File: VendorListService.java    From prebid-server-java with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the cache from previously downloaded vendor lists.
 */
private Map<Integer, Map<Integer, V>> createCache(FileSystem fileSystem, String cacheDir) {
    final Map<String, String> versionToFileContent = readFileSystemCache(fileSystem, cacheDir);

    final Map<Integer, Map<Integer, V>> cache = Caffeine.newBuilder()
            .expireAfterWrite(EXPIRE_DAY_CACHE_DURATION, TimeUnit.DAYS)
            .<Integer, Map<Integer, V>>build()
            .asMap();

    for (Map.Entry<String, String> versionAndFileContent : versionToFileContent.entrySet()) {
        final T vendorList = toVendorList(versionAndFileContent.getValue());
        final Map<Integer, V> vendorIdToVendors = filterVendorIdToVendors(vendorList);

        cache.put(Integer.valueOf(versionAndFileContent.getKey()), vendorIdToVendors);
    }
    return cache;
}
 
Example #8
Source File: HttpVerticle.java    From reactive-refarch-cloudformation with Apache License 2.0 6 votes vote down vote up
private void fillCacheWithData(final RoutingContext routingContext) {
    LOGGER.info("Filling caches with data ... ");
    LOGGER.debug("Reading JSON-data");

    FileSystem fs = vertx.fileSystem();
    fs.readFile("META-INF/data.json", res -> {
       if (res.succeeded()) {
            Buffer buf = res.result();
            JsonArray jsonArray = buf.toJsonArray();
           for (Object aJsonArray : jsonArray) {
               JsonObject obj = (JsonObject) aJsonArray;
               LOGGER.debug("Sending message to cache-verticles: " + obj);
               eb.send(Constants.CACHE_STORE_EVENTBUS_ADDRESS, obj);
               eb.send(Constants.REDIS_STORE_EVENTBUS_ADDRESS, obj);
           }
       } else {
           LOGGER.info(res.cause());
       }

        HttpServerResponse response = routingContext.request().response();
        response.putHeader("content-type", "application/json");
        response.end();
    });
}
 
Example #9
Source File: RestBodyHandler.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
private void deleteFileUploads() {
  if (cleanup.compareAndSet(false, true) && handleFileUploads) {
    for (FileUpload fileUpload : context.fileUploads()) {
      FileSystem fileSystem = context.vertx().fileSystem();
      String uploadedFileName = fileUpload.uploadedFileName();
      fileSystem.exists(uploadedFileName, existResult -> {
        if (existResult.failed()) {
          LOGGER.warn("Could not detect if uploaded file exists, not deleting: " + uploadedFileName,
              existResult.cause());
        } else if (existResult.result()) {
          fileSystem.delete(uploadedFileName, deleteResult -> {
            if (deleteResult.failed()) {
              LOGGER.warn("Delete of uploaded file failed: " + uploadedFileName, deleteResult.cause());
            }
          });
        }
      });
    }
  }
}
 
Example #10
Source File: VxApiUserAuthUtil.java    From VX-API-Gateway with MIT License 6 votes vote down vote up
/**
 * 验证用户是否正确,如果正确返回json格式的用户如果不存在返回null
 * 
 * @param suser
 *            用户名字
 * @param spass
 *            用户密码
 * @param vertx
 *            vertx
 * @param handler
 *            结果
 */
public static void auth(String suser, String spass, Vertx vertx, Handler<AsyncResult<JsonObject>> handler) {
	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(suser) instanceof JsonObject) {
				JsonObject user = users.getJsonObject(suser);
				if (spass.equals(user.getString("pwd"))) {
					handler.handle(Future.<JsonObject>succeededFuture(user));
				} else {
					handler.handle(Future.<JsonObject>succeededFuture(null));
				}
			} else {
				handler.handle(Future.<JsonObject>succeededFuture(null));
			}
		} else {
			handler.handle(Future.failedFuture(res.cause()));
		}
	});
}
 
Example #11
Source File: MainApiVerticle.java    From swaggy-jenkins with MIT License 6 votes vote down vote up
@Override
public void start(Future<Void> startFuture) throws Exception {
    Json.mapper.registerModule(new JavaTimeModule());
    FileSystem vertxFileSystem = vertx.fileSystem();
    vertxFileSystem.readFile("openapi.json", readFile -> {
        if (readFile.succeeded()) {
            Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8")));
            Router swaggerRouter = SwaggerRouter.swaggerRouter(router, swagger, vertx.eventBus(), new OperationIdServiceIdResolver());

            deployVerticles(startFuture);

            vertx.createHttpServer()
                .requestHandler(swaggerRouter::accept) 
                .listen(serverPort, h -> {
                    if (h.succeeded()) {
                        startFuture.complete();
                    } else {
                        startFuture.fail(h.cause());
                    }
                });
        } else {
        	startFuture.fail(readFile.cause());
        }
    });        		        
}
 
Example #12
Source File: BasicAuthTest.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void afterClass(TestContext context) {
    Async after = context.async();
    httpServer.close(completionHandler -> {
        if (completionHandler.succeeded()) {
            FileSystem vertxFileSystem = vertx.fileSystem();
            vertxFileSystem.deleteRecursive(".vertx", true, vertxDir -> {
                if (vertxDir.succeeded()) {
                    after.complete();
                } else {
                    context.fail(vertxDir.cause());
                }
            });
        }
    });
}
 
Example #13
Source File: ChainingAuthTest.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void afterClass(TestContext context) {
    Async after = context.async();
    httpServer.close(completionHandler -> {
        if (completionHandler.succeeded()) {
            FileSystem vertxFileSystem = vertx.fileSystem();
            vertxFileSystem.deleteRecursive(".vertx", true, vertxDir -> {
                if (vertxDir.succeeded()) {
                    after.complete();
                } else {
                    context.fail(vertxDir.cause());
                }
            });
        }
    });
}
 
Example #14
Source File: ApiKeyAuthTest.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void afterClass(TestContext context) {
    Async after = context.async();
    httpServer.close(completionHandler -> {
        if (completionHandler.succeeded()) {
            FileSystem vertxFileSystem = vertx.fileSystem();
            vertxFileSystem.deleteRecursive(".vertx", true, vertxDir -> {
                if (vertxDir.succeeded()) {
                    after.complete();
                } else {
                    context.fail(vertxDir.cause());
                }
            });
        }
    });
}
 
Example #15
Source File: ErrorHandlingTest.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void afterClass(TestContext context) {
    Async after = context.async();
    httpServer.close(completionHandler -> {
        if (completionHandler.succeeded()) {
            FileSystem vertxFileSystem = vertx.fileSystem();
            vertxFileSystem.deleteRecursive(".vertx", true, vertxDir -> {
                if (vertxDir.succeeded()) {
                    after.complete();
                } else {
                    context.fail(vertxDir.cause());
                }
            });
        }
    });
}
 
Example #16
Source File: HeaderParameterExtractorTest.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void afterClass(TestContext context) {
    Async after = context.async();
    httpServer.close(completionHandler -> {
        if (completionHandler.succeeded()) {
            FileSystem vertxFileSystem = vertx.fileSystem();
            vertxFileSystem.deleteRecursive(".vertx", true, vertxDir -> {
                if (vertxDir.succeeded()) {
                    after.complete();
                } else {
                    context.fail(vertxDir.cause());
                }
            });
        }
    });

}
 
Example #17
Source File: BodyParameterExtractorTest.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void afterClass(TestContext context) {
    Async after = context.async();
    httpServer.close(completionHandler -> {
        if (completionHandler.succeeded()) {
            FileSystem vertxFileSystem = vertx.fileSystem();
            vertxFileSystem.deleteRecursive(".vertx", true, vertxDir -> {
                if (vertxDir.succeeded()) {
                    after.complete();
                } else {
                    context.fail(vertxDir.cause());
                }
            });
        }
    });

}
 
Example #18
Source File: PathParameterExtractorTest.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void afterClass(TestContext context) {
    Async after = context.async();
    httpServer.close(completionHandler -> {
        if (completionHandler.succeeded()) {
            FileSystem vertxFileSystem = vertx.fileSystem();
            vertxFileSystem.deleteRecursive(".vertx", true, vertxDir -> {
                if (vertxDir.succeeded()) {
                    after.complete();
                } else {
                    context.fail(vertxDir.cause());
                }
            });
        }
    });

}
 
Example #19
Source File: QueryParameterExtractorTest.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void afterClass(TestContext context) {
    Async after = context.async();
    httpServer.close(completionHandler -> {
        if (completionHandler.succeeded()) {
            FileSystem vertxFileSystem = vertx.fileSystem();
            vertxFileSystem.deleteRecursive(".vertx", true, vertxDir -> {
                if (vertxDir.succeeded()) {
                    after.complete();
                } else {
                    context.fail(vertxDir.cause());
                }
            });
        }
    });

}
 
Example #20
Source File: FormParameterExtractorTest.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void afterClass(TestContext context) {
    Async after = context.async();
    httpServer.close(completionHandler -> {
        if (completionHandler.succeeded()) {
            FileSystem vertxFileSystem = vertx.fileSystem();
            vertxFileSystem.deleteRecursive("file-uploads", true, deletedDir -> {
                if (deletedDir.succeeded()) {
                    vertxFileSystem.deleteRecursive(".vertx", true, vertxDir -> {
                        if (vertxDir.succeeded()) {
                            after.complete();
                        } else {
                            context.fail(vertxDir.cause());
                        }
                    });
                } else {
                    context.fail(deletedDir.cause());
                }
            });
        }
    });

}
 
Example #21
Source File: BuildRouterTest.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void afterClass(TestContext context) {
    Async after = context.async();
    httpServer.close(completionHandler -> {
        if (completionHandler.succeeded()) {
            FileSystem vertxFileSystem = vertx.fileSystem();
            vertxFileSystem.deleteRecursive(".vertx", true, vertxDir -> {
                if (vertxDir.succeeded()) {
                    after.complete();
                } else {
                    context.fail(vertxDir.cause());
                }
            });
        }
    });

}
 
Example #22
Source File: MainApiVerticle.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@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(Charset.forName("utf-8")));
            SwaggerManager.getInstance().setSwagger(swagger);
            Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver());
        
            deployVerticles(startFuture);

            vertx.createHttpServer() 
                .requestHandler(swaggerRouter::accept) 
                .listen(config().getInteger("http.port", 8080));
            startFuture.complete();
        } else {
        	startFuture.fail(readFile.cause());
        }
    });        		        
}
 
Example #23
Source File: MainApiVerticle.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@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(Charset.forName("utf-8")));
            SwaggerManager.getInstance().setSwagger(swagger);
            Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver());
        
            deployVerticles(startFuture);

            vertx.createHttpServer() 
                .requestHandler(swaggerRouter::accept) 
                .listen(config().getInteger("http.port", 8080));
            startFuture.complete();
        } else {
        	startFuture.fail(readFile.cause());
        }
    });        		        
}
 
Example #24
Source File: MainApiVerticle.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@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(Charset.forName("utf-8")));
            SwaggerManager.getInstance().setSwagger(swagger);
            Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver());
        
            deployVerticles(startFuture);

            vertx.createHttpServer() 
                .requestHandler(swaggerRouter::accept) 
                .listen(config().getInteger("http.port", 8080));
            startFuture.complete();
        } else {
        	startFuture.fail(readFile.cause());
        }
    });        		        
}
 
Example #25
Source File: MainApiVerticle.java    From vertx-swagger with Apache License 2.0 6 votes vote down vote up
@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(Charset.forName("utf-8")));
            SwaggerManager.getInstance().setSwagger(swagger);
            Router swaggerRouter = SwaggerRouter.swaggerRouter(Router.router(vertx), swagger, vertx.eventBus(), new OperationIdServiceIdResolver());
        
            deployVerticles(startFuture);

            vertx.createHttpServer() 
                .requestHandler(swaggerRouter::accept) 
                .listen(config().getInteger("http.port", 8080));
            startFuture.complete();
        } else {
        	startFuture.fail(readFile.cause());
        }
    });        		        
}
 
Example #26
Source File: FileBasedCredentialsServiceTest.java    From hono with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Sets up fixture.
 */
@BeforeEach
public void setUp() {
    fileSystem = mock(FileSystem.class);
    eventBus = mock(EventBus.class);
    vertx = mock(Vertx.class);
    when(vertx.eventBus()).thenReturn(eventBus);
    when(vertx.fileSystem()).thenReturn(fileSystem);

    this.registrationConfig = new FileBasedRegistrationConfigProperties();
    this.registrationConfig.setCacheMaxAge(30);
    this.credentialsConfig = new FileBasedCredentialsConfigProperties();
    this.credentialsConfig.setCacheMaxAge(30);

    this.registrationService = new FileBasedRegistrationService(vertx);
    this.registrationService.setConfig(registrationConfig);

    this.credentialsService = new FileBasedCredentialsService(vertx);
    this.credentialsService.setPasswordEncoder(new SpringBasedHonoPasswordEncoder());
    this.credentialsService.setConfig(credentialsConfig);

    this.svc = new FileBasedDeviceBackend(this.registrationService, this.credentialsService);
}
 
Example #27
Source File: MainApiVerticle.java    From swagger-aem with Apache License 2.0 6 votes vote down vote up
@Override
public void start(Future<Void> startFuture) throws Exception {
    Json.mapper.registerModule(new JavaTimeModule());
    FileSystem vertxFileSystem = vertx.fileSystem();
    vertxFileSystem.readFile("openapi.json", readFile -> {
        if (readFile.succeeded()) {
            Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8")));
            Router swaggerRouter = SwaggerRouter.swaggerRouter(router, swagger, vertx.eventBus(), new OperationIdServiceIdResolver());

            deployVerticles(startFuture);

            vertx.createHttpServer()
                .requestHandler(swaggerRouter::accept) 
                .listen(serverPort, h -> {
                    if (h.succeeded()) {
                        startFuture.complete();
                    } else {
                        startFuture.fail(h.cause());
                    }
                });
        } else {
        	startFuture.fail(readFile.cause());
        }
    });        		        
}
 
Example #28
Source File: FsHelper.java    From vertx-shell with Apache License 2.0 6 votes vote down vote up
void ls(Vertx vertx, String currentFile, String pathArg, Handler<AsyncResult<Map<String, FileProps>>> filesHandler) {
  Path base = currentFile != null ? new File(currentFile).toPath() : rootDir;
  String path = base.resolve(pathArg).toAbsolutePath().normalize().toString();
  vertx.executeBlocking(fut -> {
    FileSystem fs = vertx.fileSystem();
    if (fs.propsBlocking(path).isDirectory()) {
      LinkedHashMap<String, FileProps> result = new LinkedHashMap<>();
      for (String file : fs.readDirBlocking(path)) {
        result.put(file, fs.propsBlocking(file));
      }
      fut.complete(result);
    } else {
      throw new RuntimeException(path + ": No such file or directory");
    }
  }, filesHandler);
}
 
Example #29
Source File: ReportingTest.java    From vertx-unit with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testReportToFile() {
  FileSystem fs = vertx.fileSystem();
  String file = "target";
  assertTrue(fs.existsBlocking(file));
  assertTrue(fs.propsBlocking(file).isDirectory());
  suite.run(vertx, new TestOptions().addReporter(new ReportOptions().setTo("file:" + file)));
  String path = file + File.separator + "my_suite.txt";
  assertTrue(fs.existsBlocking(path));
  int count = 1000;
  while (true) {
    FileProps props = fs.propsBlocking(path);
    if (props.isRegularFile() && props.size() > 0) {
      break;
    } else {
      if (count-- > 0) {
        try {
          Thread.sleep(1);
        } catch (InterruptedException ignore) {
        }
      } else {
        fail();
      }
    }
  }
}
 
Example #30
Source File: WebClientExamples.java    From vertx-web with Apache License 2.0 6 votes vote down vote up
public void sendStream(WebClient client, FileSystem fs) {
  fs.open("content.txt", new OpenOptions(), fileRes -> {
    if (fileRes.succeeded()) {
      ReadStream<Buffer> fileStream = fileRes.result();

      String fileLen = "1024";

      // Send the file to the server using POST
      client
        .post(8080, "myserver.mycompany.com", "/some-uri")
        .putHeader("content-length", fileLen)
        .sendStream(fileStream)
        .onSuccess(res -> {
          // OK
        })
      ;
    }
  });
}