# Class Resource.FileSet

Object
FileSet

Enclosing interface:
  `Resource`

public static class Resource.FileSet extends Object
Paths to the files potentially used by the enclosing resource. They are typically the files given to the `DataStore` constructor, sometime with auxiliary files (metadata, index, etc.). `FileSet` allows efficient copies of data set from one location to another.

Note that some `FileSet` items of a given resource may be shared by the `FileSet` of another resource. Therefore, there is no guarantee that modifying or deleting a file will not impact other resources.

Since:
  1.5

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `FileSet(Path path)`
  Creates a new instance with the given path.
  `FileSet(Path[] paths)`
  Creates a new instance with the given paths.
  `FileSet(Collection<Path> paths)`
  Creates a new instance with the given paths.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Path`
  `copy(Path destDir)`
  Copies all resource files to the given directory.
  `void`
  `delete()`
  Deletes the files used by the enclosing resource.
  `Collection<Path>`
  `getPaths()`
  Returns the paths to the files potentially used by the enclosing resource.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### FileSet

    public FileSet(Path path)
    Creates a new instance with the given path. This is a convenience constructor for the common case where the data store uses exactly one file.
    Parameters:
      `paths` - the single file to be returned by `getPaths()`.

  - ### FileSet

    public FileSet(Path[] paths)
    Creates a new instance with the given paths.
    Parameters:
      `paths` - the files to be returned by `getPaths()`.

  - ### FileSet

    public FileSet(Collection<Path> paths)
    Creates a new instance with the given paths. The content of the given collection is copied.
    Parameters:
      `paths` - the files to be returned by `getPaths()`.

- ## Method Details

  - ### getPaths

    public Collection<Path> getPaths()
    Returns the paths to the files potentially used by the enclosing resource. The first file in the returned collection should be the main file given to the `DataStore` constructor or opened by other kinds of resource. All other files, if any, may be auxiliary files such as metadata or index. The files are not necessarily in the same directory, and the same files may be used by more than one resource.

    The returned paths should be regular files instead of directories, unless the enclosing resource is designed for using the content of the whole directory. The collection should not contain non-existent files.

    Returns:
      paths to the files potentially used by the enclosing resource.

  - ### copy

    public Path copy(Path destDir) throws IOException
    Copies all resource files to the given directory. The copied files are usually the files returned by `getPaths()`, but details may very depending on the `DataStore` implementation. It is recommended to invoke this method only when the `DataStore` is closed.

    Limitations:

    - This method does not overwrite existing files or sub-directories. If a destination already exists, an exception should be thrown.
    - This copy operation is not atomic. If an exception is thrown, some files may be only partially copied or not created at all.
    This method can be used for exporting the resource to a ZIP file if the given destination directory is associated to the file system of the `jdk​.zipfs` module.

    #### Default implementation

    The default implementation performs a copy operation for each item returned by
    invalid reference

        #getPath()

    . If those source files are in different directories, the default implementation reproduces the directory structure which is below the common parent of all source files.
    Parameters:
      `destDir` - the directory where to copy the resource files.
    Returns:
      the copied main file. May be in a sub-directory of `destDir`.
    Throws:
      `FileAlreadyExistsException` - if a destination file or directory already exists.
      `IOException` - if another error occurred while copying the files.
    See Also:
      - `Files​.copy(Path, Path, CopyOption...)`

  - ### delete

    public void delete() throws IOException
    Deletes the files used by the enclosing resource. The `DataStore` that contains the resource should be closed before to invoke this method. This is not an atomic operation. If an exception is thrown, some files may still remain.

    #### Default implementation

    The default implementation deletes the files returned by `getPaths()` that are in the same directory or a sub-directory of the main file. Files in parent directory are not deleted, because they are often files shared by many resources (e.g. a global `metadata​.xml` file).
    Throws:
      `IOException` - if another error occurred while deleting a file.
    See Also:
      - `Files​.delete(Path)`