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 Data­Store constructor, sometime with auxiliary files (metadata, index, etc.). File­Set allows efficient copies of data set from one location to another.

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

Since:
1.5
  • 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 get­Paths().
    • FileSet

      public FileSet(Path[] paths)
      Creates a new instance with the given paths.
      Parameters:
      paths - the files to be returned by get­Paths().
    • 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 get­Paths().
  • 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 Data­Store 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 get­Paths(), but details may very depending on the Data­Store implementation. It is recommended to invoke this method only when the Data­Store 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
      #get­Path()
      . 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:
      dest­Dir - the directory where to copy the resource files.
      Returns:
      the copied main file. May be in a sub-directory of dest­Dir.
      Throws:
      File­Already­Exists­Exception - if a destination file or directory already exists.
      IOException - if another error occurred while copying the files.
      See Also:
    • delete

      public void delete() throws IOException
      Deletes the files used by the enclosing resource. The Data­Store 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 get­Paths() 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: