Java Code Examples for io.vertx.core.file.FileSystem#existsBlocking()
The following examples show how to use
io.vertx.core.file.FileSystem#existsBlocking() .
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: VertxVaadinService.java From vertx-vaadin with MIT License | 6 votes |
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 2
Source File: VertxVaadinService.java From vertx-vaadin with MIT License | 6 votes |
@Override public InputStream getThemeResourceAsStream(UI uI, String themeName, String resource) { String filename = VaadinServlet.THEME_DIR_PATH + '/' + themeName + "/" + resource; String normalized = Paths.get(filename).normalize().toString(); if (!normalized.startsWith("VAADIN/") || normalized.contains("/../")) { throw new VertxException(String.format( "Requested resource [%s] not accessible in the VAADIN directory or access to it is forbidden.", filename)); } FileSystem fileSystem = getVertx().fileSystem(); if (fileSystem.existsBlocking(filename)) { return new ByteArrayInputStream(fileSystem.readFileBlocking(filename).getBytes()); } return null; }
Example 3
Source File: VertxVaadinService.java From vertx-vaadin with MIT License | 5 votes |
private URL tryResolveFile(String path) { FileSystem fileSystem = getVertx().fileSystem(); String relativePath = makePathRelative(path); if (fileSystem.existsBlocking(relativePath)) { try { return new FileResolver() .resolveFile(relativePath).toURI().toURL(); } catch (MalformedURLException e) { e.printStackTrace(); } } return null; }
Example 4
Source File: RemoteFileSyncer.java From prebid-server-java with Apache License 2.0 | 5 votes |
/** * Creates if doesn't exists and checks write permissions for the given directory. */ private static void createAndCheckWritePermissionsFor(FileSystem fileSystem, String filePath) { try { final String dirPath = Paths.get(filePath).getParent().toString(); final FileProps props = fileSystem.existsBlocking(dirPath) ? fileSystem.propsBlocking(dirPath) : null; if (props == null || !props.isDirectory()) { fileSystem.mkdirsBlocking(dirPath); } else if (!Files.isWritable(Paths.get(dirPath))) { throw new PreBidException(String.format("No write permissions for directory: %s", dirPath)); } } catch (FileSystemException | InvalidPathException e) { throw new PreBidException(String.format("Cannot create directory for file: %s", filePath), e); } }
Example 5
Source File: VendorListService.java From prebid-server-java with Apache License 2.0 | 5 votes |
/** * Creates if doesn't exists and checks write permissions for the given directory. */ private static void createAndCheckWritePermissionsFor(FileSystem fileSystem, String dir) { final FileProps props = fileSystem.existsBlocking(dir) ? fileSystem.propsBlocking(dir) : null; if (props == null || !props.isDirectory()) { try { fileSystem.mkdirsBlocking(dir); } catch (FileSystemException e) { throw new PreBidException(String.format("Cannot create directory: %s", dir), e); } } else if (!Files.isWritable(Paths.get(dir))) { throw new PreBidException(String.format("No write permissions for directory: %s", dir)); } }
Example 6
Source File: RestBodyHandler.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
private void makeUploadDir(FileSystem fileSystem) { // *** cse begin *** if (uploadsDir == null) { return; } // *** cse end *** if (!fileSystem.existsBlocking(uploadsDir)) { fileSystem.mkdirsBlocking(uploadsDir); } }
Example 7
Source File: FaviconHandlerImpl.java From vertx-web with Apache License 2.0 | 5 votes |
private Buffer readFile(FileSystem fs, String path) { if (fs.existsBlocking(path)) { return fs.readFileBlocking(path); } else { throw new RuntimeException(path + " not found!"); } }
Example 8
Source File: FileResponseWriter.java From rest.vertx with Apache License 2.0 | 4 votes |
protected boolean fileExists(RoutingContext context, String file) { FileSystem fs = context.vertx().fileSystem(); return fs.existsBlocking(file); }
Example 9
Source File: BodyHandlerImpl.java From vertx-web with Apache License 2.0 | 4 votes |
private void makeUploadDir(FileSystem fileSystem) { if (!fileSystem.existsBlocking(uploadsDir)) { fileSystem.mkdirsBlocking(uploadsDir); } }