use of java.nio.file.attribute.BasicFileAttributes in project buck by facebook.
the class ProjectFilesystemTest method testWalkFileTreeWhenProjectRootIsWorkingDir.
@Test
public void testWalkFileTreeWhenProjectRootIsWorkingDir() throws IOException {
ProjectFilesystem projectFilesystem = new ProjectFilesystem(Paths.get(".").toAbsolutePath());
final ImmutableList.Builder<String> fileNames = ImmutableList.builder();
Path pathRelativeToProjectRoot = Paths.get("test/com/facebook/buck/io/testdata/directory_traversal_ignore_paths");
projectFilesystem.walkRelativeFileTree(pathRelativeToProjectRoot, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
fileNames.add(file.getFileName().toString());
return FileVisitResult.CONTINUE;
}
});
assertThat(fileNames.build(), containsInAnyOrder("file", "a_file", "b_file", "b_c_file", "b_d_file"));
}
use of java.nio.file.attribute.BasicFileAttributes in project elasticsearch-jdbc by jprante.
the class NodeTestUtils method deleteFiles.
private static void deleteFiles() throws IOException {
Path directory = Paths.get(System.getProperty("path.home") + "/data");
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
}
use of java.nio.file.attribute.BasicFileAttributes in project neo4j by neo4j.
the class FileVisitorsDecoratorsTest method shouldDelegatePreVisitDirectory.
@Test
public void shouldDelegatePreVisitDirectory() throws IOException {
Path dir = Paths.get("some-dir");
BasicFileAttributes attrs = mock(BasicFileAttributes.class);
decorator.preVisitDirectory(dir, attrs);
verify(wrapped).preVisitDirectory(dir, attrs);
}
use of java.nio.file.attribute.BasicFileAttributes in project dex2jar by pxb1988.
the class WebApp method main.
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
if (args.length < 2) {
System.out.println("webapp pathToWebApp config [ignoreJarConfig]");
return;
}
File webApp = new File(args[0]);
File config = new File(args[1]);
Path jarIgnore = args.length > 2 ? new File(args[2]).toPath() : null;
Path clz = new File(webApp, "WEB-INF/classes").toPath();
Path tmpClz = new File(webApp, "WEB-INF/tmp-classes").toPath();
final InvocationWeaver ro = (InvocationWeaver) new InvocationWeaver().withConfig(config.toPath());
Files.deleteIfExists(tmpClz);
copyDirectory(clz, tmpClz);
System.out.println("InvocationWeaver from [" + tmpClz + "] to [" + clz + "]");
ro.wave(tmpClz, clz);
Files.deleteIfExists(tmpClz);
final File lib = new File(webApp, "WEB-INF/lib");
Path tmpLib = new File(webApp, "WEB-INF/Nlib").toPath();
final Set<String> ignores = new HashSet<String>();
if (jarIgnore != null && Files.exists(jarIgnore)) {
ignores.addAll(Files.readAllLines(jarIgnore, StandardCharsets.UTF_8));
} else {
System.out.println("ignoreJarConfig ignored");
}
Files.deleteIfExists(tmpLib);
copyDirectory(lib.toPath(), tmpLib);
Files.walkFileTree(tmpLib, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().endsWith(".jar")) {
final String s = file.getFileName().toString();
boolean ignore = false;
for (String i : ignores) {
if (s.startsWith(i)) {
ignore = true;
break;
}
}
if (!ignore) {
Path nJar = new File(lib, s).toPath();
System.out.println("InvocationWeaver from [" + file + "] to [" + nJar + "]");
ro.wave(file, nJar);
}
}
return super.visitFile(file, attrs);
}
});
Files.deleteIfExists(tmpLib);
}
use of java.nio.file.attribute.BasicFileAttributes in project robovm by robovm.
the class AfcClient method upload.
/**
* Uploads a local file or directory to the device.
*
* @param localFile the file or directory to upload.
* @param targetPath the path of the directory on the device where to place
* the uploaded files.
* @param callback callback which will receive progress and status updates.
* If <code>null</code> no progress will be reported.
*/
public void upload(File localFile, final String targetPath, final UploadProgressCallback callback) throws IOException {
makeDirectory(targetPath);
final Path root = localFile.toPath().getParent();
// 64k seems to be a good buffer size. If smaller we will not get
// acceptable write speeds.
final byte[] buffer = new byte[64 * 1024];
class FileCounterVisitor extends SimpleFileVisitor<Path> {
int count;
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
count++;
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
count++;
return FileVisitResult.CONTINUE;
}
}
FileCounterVisitor visitor = new FileCounterVisitor();
if (callback != null) {
Files.walkFileTree(localFile.toPath(), visitor);
}
try {
final int fileCount = visitor.count;
Files.walkFileTree(localFile.toPath(), new SimpleFileVisitor<Path>() {
int filesUploaded = 0;
private void reportProgress(Path path) {
if (callback != null) {
callback.progress(path.toFile(), 100 * filesUploaded / fileCount);
}
filesUploaded++;
}
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
reportProgress(dir);
String deviceDir = toAbsoluteDevicePath(targetPath, root.relativize(dir));
makeDirectory(deviceDir);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
reportProgress(file);
String deviceFile = toAbsoluteDevicePath(targetPath, root.relativize(file));
if (Files.isSymbolicLink(file)) {
Path linkTargetPath = Files.readSymbolicLink(file);
makeLink(AfcLinkType.AFC_SYMLINK, toRelativeDevicePath(linkTargetPath), deviceFile);
} else if (Files.isRegularFile(file, LinkOption.NOFOLLOW_LINKS)) {
long fd = fileOpen(deviceFile, AfcFileMode.AFC_FOPEN_WRONLY);
try (InputStream is = Files.newInputStream(file)) {
int n = 0;
while ((n = is.read(buffer)) != -1) {
fileWrite(fd, buffer, 0, n);
}
} finally {
fileClose(fd);
}
}
return FileVisitResult.CONTINUE;
}
});
if (callback != null) {
callback.success();
}
} catch (IOException e) {
if (callback != null) {
callback.error(e.getMessage());
}
throw e;
} catch (LibIMobileDeviceException e) {
if (callback != null) {
callback.error(e.getMessage());
}
throw e;
}
}
Aggregations