-
-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Java NIO to copy report resources.
- Loading branch information
Showing
2 changed files
with
65 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
core/src/main/java/net/thucydides/core/reports/util/CopyDirectory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.thucydides.core.reports.util; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.*; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
|
||
public class CopyDirectory extends SimpleFileVisitor<Path> { | ||
|
||
private Path source; | ||
private Path target; | ||
|
||
public CopyDirectory(Path source, Path target) { | ||
this.source = source; | ||
this.target = target; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attributes) | ||
throws IOException { | ||
if (!Files.exists(target.resolve(source.relativize(file)))) { | ||
Files.copy(file, target.resolve(source.relativize(file))); | ||
} | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult preVisitDirectory(Path directory, | ||
BasicFileAttributes attributes) throws IOException { | ||
Path targetDirectory = target.resolve(source.relativize(directory)); | ||
try { | ||
Files.copy(directory, targetDirectory); | ||
} catch (FileAlreadyExistsException e) { | ||
if (!Files.isDirectory(targetDirectory)) { | ||
throw e; | ||
} | ||
} | ||
return FileVisitResult.CONTINUE; | ||
} | ||
} |