public final class IO extends IOImpl
Class containing functionality for input and output elements.
See Also:
  • Field Details

    • EMPTY_EXTENSIONS

      public static final String[] EMPTY_EXTENSIONS
      Empty extensions array
    • EXTENSION_IDENTIFIER

      public static final char EXTENSION_IDENTIFIER
      Character used to identify all file extensions
      See Also:
  • Method Details

    • getFilename

      @NotNull public static @NotNull String getFilename(@NotNull @NotNull Path location)
      Returns the location name
      Parameters:
      location - the location to inspect
      Returns:
      the name of the entry
    • getFilename

      @NotNull public static @NotNull String getFilename(@NotNull @NotNull File file)
      Returns the file name
      Parameters:
      file - the file object
      Returns:
      the name of the entry
    • getFilename

      @NotNull public static @NotNull String getFilename(@NotNull @NotNull ZipEntry entry)
      Returns the entry name of a zip file
      Parameters:
      entry - the entry file object
      Returns:
      the name of the entry
    • getBaseName

      @NotNull public static @NotNull String getBaseName(@NotNull @NotNull Path path)
      Get the file base name, without any extension.

      Example:

      
       "build.gradle.kts" -> build
       "example.file.java" -> example
       
      Parameters:
      path - the path to analyze
      Returns:
      the file base name
    • getBaseName

      @NotNull public static @NotNull String getBaseName(@NotNull @NotNull File file)
      Get the file base name, without any extension.

      Example:

      
       "build.gradle.kts" -> build
       "example.file.java" -> example
       
      Parameters:
      file - the file to analyze
      Returns:
      the file base name
    • getBaseName

      @NotNull public static @NotNull String getBaseName(@NotNull @NotNull ZipEntry entry)
      Get the file base name, without any extension.

      Example:

      
       "build.gradle.kts" -> build
       "example.file.java" -> example
       
      Parameters:
      entry - the zip entry to analyze
      Returns:
      the entry base name
    • getAllExtensions

      @Contract("_ -> new") public static String @NotNull [] getAllExtensions(@NotNull @NotNull Path path)
      Returns all existing extensions in a file.

      Example:

      
       "build.gradle.kts" -> [gradle, kts]
       "example.file.java" -> [file, java]
       
      Parameters:
      path - the path to analyze
      Returns:
      all file extensions
    • getAllExtensions

      @Contract("_ -> new") public static String @NotNull [] getAllExtensions(@NotNull @NotNull File file)
      Returns all existing extensions in a file.

      Example:

      
       "build.gradle.kts" -> [gradle, kts]
       "example.file.java" -> [file, java]
       
      Parameters:
      file - the file to analyze
      Returns:
      all file extensions
    • getAllExtensions

      @Contract("_ -> new") public static String @NotNull [] getAllExtensions(@NotNull @NotNull ZipEntry entry)
      Returns all existing extensions in a zip entry object.

      Example:

      
       "build.gradle.kts" -> [gradle, kts]
       "example.file.java" -> [file, java]
       
      Parameters:
      entry - the entry to analyze
      Returns:
      all file extensions
    • getExtension

      @NotNull public static @NotNull Optional<String> getExtension(@NotNull @NotNull Path path)
      Returns the file extension.

      Example:

      
       "build.gradle.kts" -> Optional["kts"]
       "example.file.java" -> Optional["java"]
       "binary_file" -> Optional[empty]
       
      Parameters:
      path - the path to analyze
      Returns:
      returns the file extension or Optional.empty() if the extension not exists
    • getExtension

      @NotNull public static @NotNull Optional<String> getExtension(@NotNull @NotNull File file)
      Returns the file extension.

      Example:

      
       "build.gradle.kts" -> Optional["kts"]
       "example.file.java" -> Optional["java"]
       "binary_file" -> Optional[empty]
       
      Parameters:
      file - the file to analyze
      Returns:
      returns the file extension or Optional.empty() if the extension not exists
    • getExtension

      @NotNull public static @NotNull Optional<String> getExtension(@NotNull @NotNull ZipEntry entry)
      Returns the zip entry extension.

      Example:

      
       "build.gradle.kts" -> Optional["kts"]
       "example.file.java" -> Optional["java"]
       "binary_file" -> Optional[empty]
       
      Parameters:
      entry - the zip entry to analyze
      Returns:
      returns the file extension or Optional.empty() if the extension not exists
    • getExtensionUnsafe

      @NotNull public static @NotNull String getExtensionUnsafe(@NotNull @NotNull Path path)
      Returns the file extension
      Parameters:
      path - the path to analyze
      Returns:
      returns the file extension or empty string if the extension not exists
    • getExtensionUnsafe

      @NotNull public static @NotNull String getExtensionUnsafe(@NotNull @NotNull File file)
      Returns the file extension
      Parameters:
      file - the path to analyze
      Returns:
      returns the file extension or empty string if the extension not exists
    • getExtensionUnsafe

      @NotNull public static @NotNull String getExtensionUnsafe(@NotNull @NotNull ZipEntry entry)
      Returns the zip entry extension
      Parameters:
      entry - the path to analyze
      Returns:
      returns the zip entry extension or empty string if the extension not exists
    • resolveUserPath

      @NotNull public static @NotNull Path resolveUserPath(String @NotNull ... location)
      Returns a specific path within the user's folder.
      Parameters:
      location - the path to resolve
      Returns:
      the resolved user relative path
    • getUserPath

      @NotNull public static @NotNull Path getUserPath()
      Depending on the operating system, it returns the path of the current user.
      Returns:
      the path to the current user's folder.
    • walkDir

      @SafeVarargs @NotNull public static @NotNull Stream<Path> walkDir(@NotNull @NotNull Path location, boolean recursive, Predicate<Path> @NotNull ... predicates) throws IOException
      Generates a stream where it recursively iterates through all the directories within the given destination.
      Parameters:
      location - base directory
      recursive - determines if the stream is required to be recursive or just the first directory
      predicates - filters applied to the stream
      Returns:
      a stream with all the given settings
      Throws:
      IOException - error if directory not exists or location is not a valid directory
      See Also:
    • walkDirArr

      @SafeVarargs public static Path @NotNull [] walkDirArr(@NotNull @NotNull Path location, boolean recursive, Predicate<Path> @NotNull ... predicates) throws IOException
      Generates an array where it recursively iterates through all the directories within the given destination.
      Parameters:
      location - base directory
      recursive - determines if the stream is required to be recursive or just the first directory
      predicates - filters applied to the stream
      Returns:
      an array with all files with the given data configuration
      Throws:
      IOException - error if directory not exists or location is not a valid directory
      See Also:
    • getFilesystem

      @NotNull public static @NotNull FileSystem getFilesystem(@NotNull @NotNull URL url) throws IOException
      Returns a valid file system depending on the scheme of the given url
      Parameters:
      url - the url to inspect
      Returns:
      valid filesystem
      Throws:
      IOException - error if url schema is not supported
    • getFilesystem

      @NotNull public static @NotNull FileSystem getFilesystem(@NotNull @NotNull URI uri) throws IOException
      Returns a valid file system depending on the scheme of the given url
      Parameters:
      uri - the url to inspect
      Returns:
      valid filesystem
      Throws:
      IOException - error if url schema is not supported
    • pathOf

      @NotNull public static @NotNull Path pathOf(@NotNull @NotNull URL url) throws IOException
      Returns the path of an url in the file system (if the scheme is supported).

      If the schema is a jar file, the virtual representation of the file as a directory will be returned.

      Parameters:
      url - the url to inspect
      Returns:
      a valid file path
      Throws:
      IOException - error if given url is not supported
    • pathOf

      @NotNull public static @NotNull Path pathOf(@NotNull @NotNull URI uri) throws IOException
      Returns the path of an url in the file system (if the scheme is supported).

      If the schema is a jar file, the virtual representation of the file as a directory will be returned.

      Parameters:
      uri - the url to inspect
      Returns:
      a valid file path
      Throws:
      IOException - error if given url is not supported