26package jau.test.junit.util;
28import java.io.BufferedInputStream;
30import java.io.FileInputStream;
31import java.io.IOException;
32import java.io.InputStream;
33import java.util.ArrayList;
36import org.jau.io.IOUtil;
46 public final List<File>
srcFiles =
new ArrayList<File>();
47 public final List<File>
dstFiles =
new ArrayList<File>();
49 public void dump(
final String prefix,
final boolean folderOnly) {
50 System.err.println(prefix+
"Total bytes: "+
totalBytes);
51 System.err.println(prefix+
"Total files: "+
totalFiles);
52 System.err.println(prefix+
"Total folder: "+
totalFolders);
54 System.err.println(prefix+
"Tracking: "+
trackFiles);
56 for(
int i=0; i<
srcFiles.size(); i++) {
59 if( !folderOnly || src.isDirectory() ) {
60 System.err.printf(
"%s\t src %4d: %s%n", prefix, i, src.toString());
61 System.err.printf(
"%s\t dst %4d: %s%n%n", prefix, i, dst.toString());
67 public static CopyStats copy(
final File src,
final File dest,
final int maxDepth,
final boolean trackFiles)
throws IOException {
69 cs.maxDepth = maxDepth;
70 cs.trackFiles = trackFiles;
74 private static void copy(
final File src,
final File dest,
final CopyStats stats)
throws IOException {
75 if(src.isDirectory()){
76 if( stats.maxDepth >= 0 && stats.currentDepth >= stats.maxDepth ) {
80 if( stats.trackFiles ) {
81 stats.srcFiles.add(src);
82 stats.dstFiles.add(dest);
88 final String fileNames[] = src.list();
89 for (
int i=0; i<fileNames.length; i++) {
90 final String fileName = fileNames[i];
91 final File srcFile =
new File(src, fileName);
92 final File destFile =
new File(dest, fileName);
93 copy(srcFile, destFile, stats);
98 if( stats.trackFiles ) {
99 stats.srcFiles.add(src);
100 stats.dstFiles.add(dest);
102 final InputStream in =
new BufferedInputStream(
new FileInputStream(src));
104 stats.totalBytes += IOUtil.copyStream2File(in, dest, 0);
void dump(final String prefix, final boolean folderOnly)
final List< File > srcFiles
final List< File > dstFiles
static CopyStats copy(final File src, final File dest, final int maxDepth, final boolean trackFiles)