public boolean isEmpty(final IOService ioService, Path dirPath) throws IOException { if (dirPath == null) return true; final DirectoryStream<Path> children = ioService.newDirectoryStream(dirPath); if (children == null) return true; Iterator<Path> iterator = children.iterator(); return iterator == null || !iterator.hasNext(); }
@Override public ProjectType getProjectType(Path projectRootPath) { try (DirectoryStream<org.uberfire.java.nio.file.Path> paths = ioService.newDirectoryStream(Paths.convert(projectRootPath), f -> f.getFileName().toString().startsWith("."))) { return ProjectType.fromFileName(StreamSupport.stream(paths.spliterator(), false) .map(Paths::convert) .map(Path::getFileName) .findFirst() ).orElse(null); } } }
private DirectoryStream<Path> getDirectoryStreamForFilesWithParticularExtension(final Path dir, final String extension) { return ioService.newDirectoryStream(dir, entry -> { if (!Files.isDirectory(entry) && !entry.getFileName().toString().startsWith(".") && entry.getFileName().toString().endsWith(extension)) { return true; } return false; }); }
protected boolean isCaseProject(Path rootProjectPath) { org.uberfire.java.nio.file.DirectoryStream<Path> found = ioService.newDirectoryStream(rootProjectPath, f -> f.endsWith(CASE_PROJECT_DOT_FILE)); return found.iterator().hasNext(); } }
protected boolean isCaseProject(Path rootProjectPath) { org.uberfire.java.nio.file.DirectoryStream<Path> found = ioService.newDirectoryStream(rootProjectPath, f -> f.endsWith(CASE_PROJECT_DOT_FILE)); return found.iterator().hasNext(); } }
boolean hasAssets(final Path packagePath) { final org.uberfire.java.nio.file.Path nioPackagePath = Paths.convert(packagePath); if (Files.exists(nioPackagePath)) { final DirectoryStream<org.uberfire.java.nio.file.Path> nioPaths = ioService.newDirectoryStream(nioPackagePath, regularFileFilter); for (org.uberfire.java.nio.file.Path nioPath : nioPaths) { return true; } } return false; }
@Override public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<Path> filter) throws IllegalArgumentException, NotDirectoryException, IOException, SecurityException { if (!authManager.authorize(toResource(dir), getUser())) { throw new SecurityException(); } return service.newDirectoryStream(dir, filter); }
@Override public DirectoryStream<Path> newDirectoryStream(Path dir) throws IllegalArgumentException, NotDirectoryException, IOException, SecurityException { if (!authManager.authorize(toResource(dir), getUser())) { throw new SecurityException(); } return service.newDirectoryStream(dir); }
@Override public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<Path> filter) throws IllegalArgumentException, NotDirectoryException, IOException, SecurityException { if (!authManager.authorize(toResource(dir), getUser())) { throw new SecurityException(); } return service.newDirectoryStream(dir, filter); }
@Override public DirectoryStream<Path> newDirectoryStream(Path dir) throws IllegalArgumentException, NotDirectoryException, IOException, SecurityException { if (!authManager.authorize(toResource(dir), getUser())) { throw new SecurityException(); } return service.newDirectoryStream(dir); }
private Set<Media> loadMediaLibrary( final String pluginName ) { try { final Path rootPlugin = getPluginPath( pluginName ); final DirectoryStream<Path> stream = ioService.newDirectoryStream( getMediaRoot( rootPlugin ) ); final Set<Media> result = new HashSet<Media>(); for ( final Path path : stream ) { result.add( new Media( "/" + getMediaServletURI() + pluginName + "/media/" + path.getFileName(), convert( path ) ) ); } return result; } catch ( final NotDirectoryException exception ) { return Collections.emptySet(); } }
@Override public DirectoryStream<Path> newDirectoryStream(final Path dir) throws IllegalArgumentException, NotDirectoryException, IOException { final Iterator<org.uberfire.java.nio.file.Path> content = ioService.newDirectoryStream(Paths.convert(dir)).iterator(); return newDirectoryStream(content); }
@Before public void setUp() throws Exception { ArgumentCaptor<DirectoryStream.Filter> filter = ArgumentCaptor.forClass(DirectoryStream.Filter.class); when(ioService.newDirectoryStream(any(), filter.capture())).thenReturn(directoryStream); when(directoryStream.spliterator()).thenReturn(Arrays.asList(fsPath).spliterator()); when(projectPath.toURI()).thenReturn(DIR_URI); when(fsPath.getFileName()).thenReturn(fileName); when(fsPath.toUri()).thenReturn(new URI(FILE_URI)); when(fsPath.getFileSystem()).thenReturn(fs); when(fileName.toString()).thenReturn(FILE_NAME); tested = new BPMNDiagramServiceImpl(ioService); }
@Test public void testNewDirectoryStream() { doAnswer((Answer<org.uberfire.java.nio.file.DirectoryStream<org.uberfire.java.nio.file.Path>>) invocationOnMock -> rootDirectoryStream) .when(ioService) .newDirectoryStream(any(org.uberfire.java.nio.file.Path.class)); final DirectoryStream<Path> paths = tested.newDirectoryStream(ROOT_PATH); final Path path = paths.iterator().next(); assertEquals(ROOT_PATH, path); }
@Test public void testNewDirectoryStream() { doAnswer((Answer<org.uberfire.java.nio.file.DirectoryStream<org.uberfire.java.nio.file.Path>>) invocationOnMock -> rootDirectoryStream) .when(ioService) .newDirectoryStream(any(org.uberfire.java.nio.file.Path.class)); final DirectoryStream<Path> paths = tested.newDirectoryStream(ROOT_PATH); final Path path = paths.iterator().next(); assertEquals(ROOT_PATH, path); }
@Override public DirectoryStream<Path> newDirectoryStream(final Path dir, final DirectoryStream.Filter<Path> filter) throws IllegalArgumentException, NotDirectoryException, IOException { final Iterator<org.uberfire.java.nio.file.Path> content = ioService.newDirectoryStream(Paths.convert(dir), path -> filter.accept(Paths.convert(path))).iterator(); return newDirectoryStream(content); }
private void clearDirectory(Path directory) { if (getIoService().exists(directory)) { for (Path path : getIoService().newDirectoryStream(directory)) { boolean b = getIoService().deleteIfExists(path); } } }
@Override public void postProcess(final Path source, final Path destination) { try (DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream = ioService.newDirectoryStream(getParentFolder(source), new FileExtensionFilter(dtableGraphType.getSuffix()))) { directoryStream.forEach((path) -> updateGraphElementPath(source, destination, Paths.convert(path))); } }
@Override public void postProcess(final Path path) { try (final DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream = ioService.newDirectoryStream(getParentFolder(path), new FileExtensionFilter(dtableGraphType.getSuffix()))) { directoryStream.forEach((p) -> updateGraphReferences(path, Paths.convert(p))); } }
private void updateGraphElementPaths(final Path source, final Path destination) { try (final DirectoryStream<org.uberfire.java.nio.file.Path> directoryStream = ioService.newDirectoryStream(getParentFolder(source), new FileExtensionFilter(dtableGraphType.getSuffix()))) { directoryStream.forEach((path) -> updateGraphElementPath(source, destination, Paths.convert(path))); } }