类 ApplicationTemp

java.lang.Object
cn.taketoday.core.ApplicationTemp

public class ApplicationTemp extends Object
Provides access to an application specific temporary directory. Generally speaking different Framework applications will get different locations, however, simply restarting an application will give the same location.
从以下版本开始:
4.0 2022/2/20 23:28
作者:
Phillip Webb, Harry Yang
  • 字段详细资料

  • 构造器详细资料

    • ApplicationTemp

      public ApplicationTemp()
      Create a new ApplicationTemp instance.
    • ApplicationTemp

      public ApplicationTemp(@Nullable Class<?> sourceClass)
      Create a new ApplicationTemp instance for the specified source class.
      参数:
      sourceClass - the source class or null
  • 方法详细资料

    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • getDir

      public Path getDir() throws UncheckedIOException
      Return the directory to be used for application specific temp files.
      返回:
      the application temp directory
      抛出:
      UncheckedIOException - failed to create base temp dir
    • getDir

      public Path getDir(@Nullable String subDir) throws UncheckedIOException
      Return a sub-directory of the application temp.
      参数:
      subDir - the sub-directory name
      返回:
      a sub-directory
      抛出:
      UncheckedIOException - failed to create subdir
    • createFile

      public Path createFile(@Nullable String subDir, String prefix)
      Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. The resulting Path is associated with the same FileSystem as the given directory.

      The details as to how the name of the file is constructed is implementation dependent and therefore not specified. Where possible the prefix and suffix are used to construct candidate names in the same manner as the File.createTempFile(String, String, File) method.

      As with the File.createTempFile methods, this method is only part of a temporary-file facility. Where used as a work files, the resulting file may be opened using the DELETE_ON_CLOSE option so that the file is deleted when the appropriate close method is invoked. Alternatively, a shutdown-hook, or the File.deleteOnExit() mechanism may be used to delete the file automatically.

      The attrs parameter is optional file-attributes to set atomically when creating the file. Each attribute is identified by its name. If more than one attribute of the same name is included in the array then all but the last occurrence is ignored. When no file attributes are specified, then the resulting file may have more restrictive access permissions to files created by the File.createTempFile(String, String, File) method.

      参数:
      subDir - the path to directory in which to create the file
      prefix - the prefix string to be used in generating the file's name; may be null
      返回:
      the path to the newly created file that did not exist before this method was invoked
      抛出:
      IllegalArgumentException - if the prefix or suffix parameters cannot be used to generate a candidate file name
      UncheckedIOException - if an I/O error occurs or dir does not exist
    • createFile

      public Path createFile(@Nullable String subDir, @Nullable String prefix, @Nullable String suffix)
      Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name. The resulting Path is associated with the same FileSystem as the given directory.

      The details as to how the name of the file is constructed is implementation dependent and therefore not specified. Where possible the prefix and suffix are used to construct candidate names in the same manner as the File.createTempFile(String, String, File) method.

      As with the File.createTempFile methods, this method is only part of a temporary-file facility. Where used as a work files, the resulting file may be opened using the DELETE_ON_CLOSE option so that the file is deleted when the appropriate close method is invoked. Alternatively, a shutdown-hook, or the File.deleteOnExit() mechanism may be used to delete the file automatically.

      The attrs parameter is optional file-attributes to set atomically when creating the file. Each attribute is identified by its name. If more than one attribute of the same name is included in the array then all but the last occurrence is ignored. When no file attributes are specified, then the resulting file may have more restrictive access permissions to files created by the File.createTempFile(String, String, File) method.

      参数:
      subDir - the path to directory in which to create the file
      prefix - the prefix string to be used in generating the file's name; may be null
      suffix - the suffix string to be used in generating the file's name; may be null, in which case ".tmp" is used
      返回:
      the path to the newly created file that did not exist before this method was invoked
      抛出:
      IllegalArgumentException - if the prefix or suffix parameters cannot be used to generate a candidate file name
      UncheckedIOException - if an I/O error occurs or dir does not exist
    • getPath

      private Path getPath() throws UncheckedIOException
      抛出:
      UncheckedIOException
    • getTempSubDir

      private static String getTempSubDir(@Nullable Class<?> sourceClass)
    • createDirectory

      private Path createDirectory(Path path) throws UncheckedIOException
      抛出:
      UncheckedIOException - failed to create temp dir
    • getFileAttributes

      private FileAttribute<?>[] getFileAttributes(FileSystem fileSystem)
    • getTempDirectory

      private Path getTempDirectory()
    • createDirectory

      public static Path createDirectory(String subDir)
      Using default instance to create temp directory
    • createFile

      public static Path createFile(String prefix)
      Using default instance to create temp file