java.lang.Object
com.github.ushiosan23.jvm.io.IOUtils
-
Method Summary
Modifier and TypeMethodDescriptionGenerates a stream where it recursively iterates through all the directories within the given destination.Generates a stream where it recursively iterates through all the directories within the given destination.getAllExtensions(@NotNull Path path) Returns a text string with all the extensions of a file.getBaseName(@NotNull Path path) Returns the base name of the route.getExtension(@NotNull Path path) Returns the extension of a given file.Depending on the operating system, it returns the path of the current user.static @NotNull FileSystemgetValidFileSystem(@NotNull URI location) Try to return a valid file system.static @NotNull FileSystemgetValidFileSystem(@NotNull URL location) Try to return a valid file system.Returns a jar file as a virtual directory.Returns a jar file as a virtual directory.Returns a jar file as a virtual directory.resolveUserPath(String @NotNull ... location) Returns a specific path within the user's folder.
-
Method Details
-
getAllExtensions
Returns a text string with all the extensions of a file.Example:
Path exampleFile = Path.of("build.gradle.kts"); String extensions = IOUtils.getAllExtensions(exampleFile); System.out.println(extensions); // Result: ".gradle.kts"- Parameters:
path- Route to evaluate- Returns:
- Return all extensions of a given file
- Throws:
IllegalArgumentException- Error if path is not a valid file
-
getExtension
Returns the extension of a given file. If the path is a directory it generates an error.- Parameters:
path- Route to evaluate- Returns:
- Returns the extension of a given file.
- Throws:
IllegalArgumentException- Error if path is not a valid file
-
getBaseName
Returns the base name of the route. For directories, it will only return the name and for files the name without the extensions.- Parameters:
path- Route to evaluate- Returns:
- Returns the base name
-
getUserPath
Depending on the operating system, it returns the path of the current user.- Returns:
- Returns the path to the current user's folder.
- See Also:
-
resolveUserPath
Returns a specific path within the user's folder.- Parameters:
location- Path to search- Returns:
- Returns the resolved path
- See Also:
-
directoryWalk
@SafeVarargs @NotNull public static @NotNull Stream<Path> directoryWalk(@NotNull @NotNull Path location, boolean recursive, Predicate<Path> @NotNull ... filters) throws IOException Generates a stream where it recursively iterates through all the directories within the given destination.- Parameters:
location- Base directoryrecursive- Determines if the stream is required to be recursive or just the first directory.filters- Filters applied to the stream.- Returns:
- Returns a stream with all the given settings
- Throws:
IOException- Error if directory not exists- See Also:
-
directoryWalkArr
@SafeVarargs public static Path @NotNull [] directoryWalkArr(@NotNull @NotNull Path location, boolean recursive, Predicate<Path> @NotNull ... filters) throws IOException Generates a stream where it recursively iterates through all the directories within the given destination.- Parameters:
location- Base directoryrecursive- Determines if the stream is required to be recursive or just the first directory.filters- Filters applied to the stream.- Returns:
- Returns an array with all the given settings
- Throws:
IOException- Error if directory not exists- See Also:
-
getValidFileSystem
@NotNull public static @NotNull FileSystem getValidFileSystem(@NotNull @NotNull URL location) throws IOException, URISyntaxException Try to return a valid file system. This only works with local connections where it is possible to get files from a jar file inside a classloader.- Parameters:
location- The file to check- Returns:
- Returns a valid file system instance
- Throws:
IOException- If an I/O error occursURISyntaxException- If the url is not set correctly.
-
getValidFileSystem
@NotNull public static @NotNull FileSystem getValidFileSystem(@NotNull @NotNull URI location) throws IOException Try to return a valid file system. This only works with local connections where it is possible to get files from a jar file inside a classloader.- Parameters:
location- The file to check- Returns:
- Returns a valid file system instance
- Throws:
IOException- If an I/O error occurs
-
jarToPath
@NotNull public static @NotNull Path jarToPath(@NotNull @NotNull URL location) throws IOException, URISyntaxException Returns a jar file as a virtual directory. If the file is not a valid jar it will throw an error.- Parameters:
location- The jar file location- Returns:
- Returns a virtual jar directory
- Throws:
IOException- If an I/O error occursURISyntaxException- If the url is not set correctly.
-
jarToPath
Returns a jar file as a virtual directory. If the file is not a valid jar it will throw an error.- Parameters:
location- The jar file location- Returns:
- Returns a virtual jar directory
- Throws:
IOException- If an I/O error occurs
-
jarToPath
Returns a jar file as a virtual directory. If the file is not a valid jar it will throw an error.- Parameters:
location- The jar file location- Returns:
- Returns a virtual jar directory
- Throws:
IOException- If an I/O error occurs
-