class Directory implements Serializable {

  public void copyTo(final Directory target, final boolean incremental)
    throws IOException {

    if (!getFile().exists()) {
      throw new DirectoryException(
        "Source directory '" + getFile() + "' does not exist");
    }

    target.create();

    if (!incremental) {
      target.deleteContents();
    }

    final File[] files = listContents(s_matchAllFilesFilter, true, false);
    final StreamCopier streamCopier = new StreamCopier(4096, false);

    for (final File file : files) {
      final File source = getFile(file);
      final File destination = target.getFile(file);

      if (source.isDirectory()) {
        destination.mkdirs();
      }
      else {
        // Copy file.
        if (!incremental ||
            !destination.exists() ||
            source.lastModified() > destination.lastModified()) {

          FileInputStream in = null;
          FileOutputStream out = null;

          try {
            in = new FileInputStream(source);
            out = new FileOutputStream(destination);
            streamCopier.copy(in, out);
          }
          finally {
            Closer.close(in);
            Closer.close(out);
          }
        }
      }
    }
  }

  public  Directory();
  public  Directory(final File directory);

}