/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.io.file;

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

import org.apache.commons.io.file.Counters.PathCounters;

/**
 * Copies a source directory to a target directory.
 *
 * @since 2.7
 */
public class CopyDirectoryVisitor extends CountingPathVisitor {

    private static final CopyOption[] EMPTY_COPY_OPTIONS = new CopyOption[0];

    private final CopyOption[] copyOptions;
    private final Path sourceDirectory;
    private final Path targetDirectory;

    /**
     * Constructs a new visitor that deletes files except for the files and directories explicitly given.
     *
     * @param pathCounter How to count visits.
     * @param sourceDirectory The source directory
     * @param targetDirectory The target directory
     * @param copyOptions Specifies how the copying should be done.
     */
    public CopyDirectoryVisitor(final PathCounters pathCounter, final Path sourceDirectory, final Path targetDirectory,
            final CopyOption... copyOptions) {
        super(pathCounter);
        this.sourceDirectory = sourceDirectory;
        this.targetDirectory = targetDirectory;
        this.copyOptions = copyOptions == null ? EMPTY_COPY_OPTIONS : copyOptions.clone();
    }

    /**
     * Copies the sourceFile to the targetFile.
     *
     * @param sourceFile the source file.
     * @param targetFile the target file.
     * @throws IOException if an I/O error occurs.
     * @since 2.8.0
     */
    protected void copy(final Path sourceFile, final Path targetFile) throws IOException {
        Files.copy(sourceFile, targetFile, copyOptions);
    }

    @Override
    public FileVisitResult preVisitDirectory(final Path directory, final BasicFileAttributes attributes)
            throws IOException {
        final Path newTargetDir = targetDirectory.resolve(sourceDirectory.relativize(directory));
        if (Files.notExists(newTargetDir)) {
            Files.createDirectory(newTargetDir);
        }
        return super.preVisitDirectory(directory, attributes);
    }

    @Override
    public FileVisitResult visitFile(final Path sourceFile, final BasicFileAttributes attributes) throws IOException {
        final Path targetFile = targetDirectory.resolve(sourceDirectory.relativize(sourceFile));
        copy(sourceFile, targetFile);
        return super.visitFile(targetFile, attributes);
    }

}

@@ -1915,28 +1915,24 @@
 ry,%0A        
-    
 final CopyOp
@@ -1950,24 +1950,24 @@
 yOptions) %7B%0A
+
         supe
@@ -2549,32 +2549,603 @@
 ptions);%0A    %7D%0A%0A
+    /**%0A     * Gets the copy options.%0A     * %0A     * @return the copy options.%0A     * @since 2.8.0%0A     */%0A    public CopyOption%5B%5D getCopyOptions() %7B%0A        return copyOptions;%0A    %7D%0A%0A    /**%0A     * Gets the source directory.%0A     * %0A     * @return the source directory.%0A     * @since 2.8.0%0A     */%0A    public Path getSourceDirectory() %7B%0A        return sourceDirectory;%0A    %7D%0A%0A    /**%0A     * Gets the target directory.%0A     * %0A     * @return the target directory.%0A     * @since 2.8.0%0A     */%0A    public Path getTargetDirectory() %7B%0A        return targetDirectory;%0A    %7D%0A%0A
     @Override%0A  
@@ -3247,20 +3247,16 @@
 ibutes)%0A
-    
         

Add getters for simpler subclassing.