All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.keycloak.guides.maven.DirectoryCopyVisitor Maven / Gradle / Ivy

There is a newer version: 26.1.0
Show newest version
package org.keycloak.guides.maven;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;

public class DirectoryCopyVisitor extends SimpleFileVisitor {

	private Path targetDir;
	private Path sourceDir;

	public DirectoryCopyVisitor(Path targetDir) {
		this.targetDir = targetDir;
	}

	@Override
	public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
		if (sourceDir == null) {
			sourceDir = dir;
		} else {
			Path relativePath = sourceDir.relativize(dir);
			Files.createDirectories(targetDir.resolve(relativePath));
		}
		
		return	FileVisitResult.CONTINUE;
	}

	@Override
	public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
		Path relativePath = sourceDir.relativize(file);
		Files.copy(file, targetDir.resolve(relativePath), StandardCopyOption.REPLACE_EXISTING);
		return FileVisitResult.CONTINUE;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy