- java.lang.Object
-
- com.github.ushiosan23.jvm.io.IOUtils
-
public final class IOUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NotNull Stream<Path>directoryWalk(@NotNull Path location, boolean recursive, Predicate<Path> @NotNull ... filters)Generates a stream where it recursively iterates through all the directories within the given destination.static Path @NotNull []directoryWalkArr(@NotNull Path location, boolean recursive, Predicate<Path> @NotNull ... filters)Generates a stream where it recursively iterates through all the directories within the given destination.static @NotNull StringgetAllExtensions(Path path)Returns a text string with all the extensions of a file.static @NotNull StringgetExtension(Path path)Returns the extension of a given file.static @NotNull PathgetUserPath()Depending on the operating system, it returns the path of the current user.static @NotNull PathresolveUserPath(String @NotNull ... location)Returns a specific path within the user's folder.
-
-
-
Method Detail
-
getAllExtensions
@NotNull public static @NotNull String getAllExtensions(Path path)
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
@NotNull public static @NotNull String getExtension(Path path)
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
-
getUserPath
@NotNull public static @NotNull Path 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:
Path.of(String, String...)
-
resolveUserPath
@NotNull public static @NotNull Path resolveUserPath(String @NotNull ... location)
Returns a specific path within the user's folder.- Parameters:
location- Path to search- Returns:
- Returns the resolved path
- See Also:
Path.of(String, String...)
-
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:
Files,Files.isRegularFile(Path, LinkOption...),Files.isDirectory(Path, LinkOption...),Files.isExecutable(Path)
-
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:
Files,Files.isRegularFile(Path, LinkOption...),Files.isDirectory(Path, LinkOption...),Files.isExecutable(Path)
-
-