private void addPath(DirectoryStream<Path> directoryStream) throws IOException { for (Path subPath : directoryStream) { if (Files.isDirectory(subPath)) { addPath(Files.newDirectoryStream(subPath)); } else { addFile(subPath); } } }
@Override public boolean exists(final Path path) throws IllegalArgumentException, SecurityException { return Files.exists(path); }
private void copyFolders(final org.uberfire.java.nio.file.Path nioTargetRepositoryRoot, final org.uberfire.java.nio.file.Path originRepositoryRoot) { final RecursiveCopier copier = new RecursiveCopier(originRepositoryRoot, nioTargetRepositoryRoot); Files.walkFileTree(originRepositoryRoot, copier); }
public static String readLockedBy(final Path path) { org.uberfire.java.nio.file.Path lock = convert(PathFactory.newLock(path)); if (!Files.exists(lock)) { return null; } else { return new String(Files.readAllBytes(lock)); } }
public static String probeContentType(final Path path) throws UnsupportedOperationException, IOException, SecurityException { checkNotNull("path", path); if (notExists(path)) { throw new NoSuchFileException(path.toString()); } if (!isRegularFile(path)) { throw new NoSuchFileException(path.toString()); } throw new UnsupportedOperationException("feature not available"); }
@Override public boolean accept(final Path path) { if (!Files.isDirectory(path)) { return false; } if (next != null) { return next.accept(path); } return true; }
public FolderItem toFolderItem(final org.uberfire.java.nio.file.Path path) { if (Files.isRegularFile(path)) { final org.uberfire.backend.vfs.Path p = Paths.convert(path); return new FolderItem(p, p.getFileName(), FolderItemType.FILE, false, Paths.readLockedBy(p), Collections.<String>emptyList(), getRestrictedOperations(p)); } else if (Files.isDirectory(path)) { final org.uberfire.backend.vfs.Path p = Paths.convert(path); return new FolderItem(p, p.getFileName(), FolderItemType.FOLDER); } return null; }
@Override public DirectoryStream<Path> newDirectoryStream(final Path dir, final DirectoryStream.Filter<Path> filter) throws IllegalArgumentException, NotDirectoryException, IOException, SecurityException { return Files.newDirectoryStream(dir, filter); }
@Test public void copyIn2PathNull2() { assertThatThrownBy(() -> Files.copy(Files.newInputStream(Files.createTempFile("foo", "bar")), null, REPLACE_EXISTING)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Parameter named 'target' should be not null!"); }
@Override public boolean accept(final Path path) { if (!Files.isRegularFile(path)) { return false; } if (next != null) { return next.accept(path); } return true; }
@Test(expected = NotDirectoryException.class) public void newDirectoryStreamNotDirecotory2() { Files.newDirectoryStream(Files.createTempFile("foo", "bar"), new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path entry) throws IOException { return false; } }); }
@Override public InputStream newInputStream(final Path path, final OpenOption... options) throws IllegalArgumentException, NoSuchFileException, UnsupportedOperationException, IOException, SecurityException { return Files.newInputStream(path, options); }
@Test public void testWalker() { final Path dir = newTempDir(null); final Path file1 = Files.createTempFile(dir, "foo", "bar"); Files.createTempFile(dir, "foo", "bar"); cleanupVisitor(); Files.walkFileTree(dir, simple); assertThat(preDir.get()).isEqualTo(1); assertThat(postDir.get()).isEqualTo(1); assertThat(fileC.get()).isEqualTo(2); assertThat(failFile.get()).isEqualTo(0); cleanupVisitor(); Files.walkFileTree(file1, simple); assertThat(preDir.get()).isEqualTo(0); assertThat(postDir.get()).isEqualTo(0); assertThat(fileC.get()).isEqualTo(1); assertThat(failFile.get()).isEqualTo(0); }
@Override public byte[] readAllBytes(final Path path) throws IOException, OutOfMemoryError, SecurityException { return Files.readAllBytes(path); }
public static Path createTempDirectory(final String prefix, final FileAttribute<?>... attrs) throws IllegalArgumentException, UnsupportedOperationException, IOException, SecurityException { return createTempDirectory(TEMP_PATH, prefix, attrs); }
@Test public void exists() { final Path path = Files.createTempFile("foo", "bar"); assertThat(Files.exists(path)).isTrue(); assertThat(Files.exists(newTempDir())).isTrue(); assertThat(Files.exists(Paths.get("/some/path/here"))).isFalse(); }
@Test public void isRegularFile() { final Path path = Files.createTempFile("foo", "bar"); assertThat(Files.isRegularFile(path)).isTrue(); assertThat(Files.isRegularFile(newTempDir())).isFalse(); assertThat(Files.isRegularFile(Paths.get("/some/file"))).isFalse(); }
public static long copy(final Path source, final OutputStream out) throws IOException, SecurityException { checkNotNull("source", source); checkNotNull("out", out); final InputStream in = newInputStream(source); try { return internalCopy(in, out); } finally { try { in.close(); } catch (java.io.IOException e) { throw new IOException(e); } } }
@Test public void write() { final Path dir = newTempDir(); Path file = dir.resolve("file.txt"); Files.write(file, "content".getBytes()); assertThat(Files.readAllBytes(file)) .hasSize("content".getBytes().length) .isEqualTo("content".getBytes()); }
public BaseCompilerTest(String prjName) { try { mavenRepoPath = TestUtilMaven.getMavenRepo(); tmpRoot = Files.createTempDirectory("repo"); alternateSettingsAbsPath = new File("src/test/settings.xml").getAbsolutePath(); Path tmp = Files.createDirectories(Paths.get(tmpRoot.toString(), "dummy")); TestUtil.copyTree(Paths.get(prjName), tmp); info = new WorkspaceCompilationInfo(Paths.get(tmp.toUri())); } catch (Exception e) { logger.error(e.getMessage()); } }