@@ -69,13 +69,13 @@ public class FileUtils {
6969 private static final SimpleFileVisitor <Path > DELETE_FOLDER_VISITOR = new SimpleFileVisitor <>() {
7070
7171 @ Override
72- public FileVisitResult postVisitDirectory (final Path dir , final IOException exc ) throws IOException {
72+ public FileVisitResult postVisitDirectory (@ NotNull Path dir , @ Nullable IOException exc ) throws IOException {
7373 Files .delete (dir );
7474 return FileVisitResult .CONTINUE ;
7575 }
7676
7777 @ Override
78- public FileVisitResult visitFile (final Path file , final BasicFileAttributes attrs ) throws IOException {
78+ public FileVisitResult visitFile (@ NotNull Path file , @ NotNull BasicFileAttributes attrs ) throws IOException {
7979 Files .delete (file );
8080 return FileVisitResult .CONTINUE ;
8181 }
@@ -105,7 +105,7 @@ public static boolean isValidName(@Nullable String filename) {
105105 * @param filename the string with file name.
106106 * @return normalized file name.
107107 */
108- public static @ NotNull String normalizeName (@ Nullable final String filename ) {
108+ public static @ NotNull String normalizeName (@ Nullable String filename ) {
109109
110110 if (StringUtils .isEmpty (filename )) {
111111 return "_" ;
@@ -124,10 +124,10 @@ public static boolean isValidName(@Nullable String filename) {
124124 * @param extensions extensions filter.
125125 */
126126 public static void addFilesTo (
127- @ NotNull Array <Path > container ,
128- @ NotNull Path dir ,
129- boolean withFolders ,
130- @ Nullable String ... extensions
127+ @ NotNull Array <Path > container ,
128+ @ NotNull Path dir ,
129+ boolean withFolders ,
130+ @ Nullable String ... extensions
131131 ) {
132132
133133 if (Files .isDirectory (dir ) && withFolders ) {
@@ -139,8 +139,8 @@ public static void addFilesTo(
139139 return ;
140140 }
141141
142- try (DirectoryStream < Path > stream = Files .newDirectoryStream (dir )) {
143- for (Path path : stream ) {
142+ try (var stream = Files .newDirectoryStream (dir )) {
143+ for (var path : stream ) {
144144 if (Files .isDirectory (path )) {
145145 addFilesTo (container , path , withFolders , extensions );
146146 } else if (extensions == null || extensions .length < 1 || containsExtensions (extensions , path .getFileName ())) {
@@ -508,11 +508,11 @@ public static boolean hasExtension(@Nullable String path) {
508508 */
509509 public static @ NotNull String read (@ NotNull InputStream in ) {
510510
511- StringBuilder content = new StringBuilder ();
511+ var content = new StringBuilder ();
512512
513- try (BufferedReader reader = new BufferedReader (new InputStreamReader (in ))) {
513+ try (var reader = new BufferedReader (new InputStreamReader (in ))) {
514514
515- CharBuffer buffer = CharBuffer .allocate (512 );
515+ var buffer = CharBuffer .allocate (512 );
516516
517517 while (reader .ready ()) {
518518
@@ -660,7 +660,7 @@ public static void createDirectories(@NotNull Path directory, @NotNull FileAttri
660660 * @see Files#getLastModifiedTime(Path, LinkOption...)
661661 */
662662 public static @ NotNull FileTime getLastModifiedTime (@ NotNull Path file , @ NotNull LinkOption ... options ) {
663- return notNull (Utils .safeGet (file , options , Files ::getLastModifiedTime ));
663+ return notNull (Utils .uncheckedGet (file , options , Files ::getLastModifiedTime ));
664664 }
665665
666666 /**
@@ -697,7 +697,7 @@ public static void createDirectories(@NotNull Path directory, @NotNull FileAttri
697697 * @see Path#relativize(Path)
698698 */
699699 public static @ NotNull Path relativize (@ NotNull Path base , @ NotNull Path other ) {
700- return Utils .get (base , other , Path ::relativize );
700+ return Utils .uncheckedGet (base , other , Path ::relativize );
701701 }
702702
703703 /**
@@ -707,7 +707,7 @@ public static void createDirectories(@NotNull Path directory, @NotNull FileAttri
707707 if (base == null || other == null ) {
708708 return null ;
709709 } else {
710- return Utils .safeGet (base , other , Path ::relativize );
710+ return Utils .uncheckedGet (base , other , Path ::relativize );
711711 }
712712 }
713713
@@ -740,9 +740,9 @@ public static void createDirectories(@NotNull Path directory, @NotNull FileAttri
740740 * @see Files#createTempFile(String, String, FileAttribute[])
741741 */
742742 public static @ NotNull Path createTempFile (
743- @ NotNull String prefix ,
744- @ NotNull String suffix ,
745- @ Nullable FileAttribute <?>... attrs
743+ @ NotNull String prefix ,
744+ @ NotNull String suffix ,
745+ @ Nullable FileAttribute <?>... attrs
746746 ) {
747747 try {
748748 return Files .createTempFile (prefix , suffix , attrs );
@@ -760,8 +760,8 @@ public static void createDirectories(@NotNull Path directory, @NotNull FileAttri
760760 public static void forEach (@ NotNull Path directory , @ NotNull Consumer <@ NotNull Path > consumer ) {
761761 validateDirectory (directory );
762762
763- try (DirectoryStream < Path > stream = Files .newDirectoryStream (directory )) {
764- for (Path path : stream ) {
763+ try (var stream = Files .newDirectoryStream (directory )) {
764+ for (var path : stream ) {
765765 consumer .accept (path );
766766 }
767767 } catch (IOException e ) {
@@ -786,14 +786,14 @@ private static void validateDirectory(@NotNull Path directory) {
786786 * @param <T> the argument's type.
787787 */
788788 public static <T > void forEach (
789- @ NotNull Path directory ,
790- @ NotNull T argument ,
791- @ NotNull BiConsumer <@ NotNull Path , @ NotNull T > consumer
789+ @ NotNull Path directory ,
790+ @ NotNull T argument ,
791+ @ NotNull BiConsumer <@ NotNull Path , @ NotNull T > consumer
792792 ) {
793793 validateDirectory (directory );
794794
795- try (DirectoryStream < Path > stream = Files .newDirectoryStream (directory )) {
796- for (Path path : stream ) {
795+ try (var stream = Files .newDirectoryStream (directory )) {
796+ for (var path : stream ) {
797797 consumer .accept (path , argument );
798798 }
799799 } catch (IOException e ) {
@@ -830,14 +830,14 @@ public static <T> void forEach(
830830 * @param <T> the argument's type.
831831 */
832832 public static <T > void forEachR (
833- @ NotNull Path directory ,
834- @ NotNull T argument ,
835- @ NotNull BiConsumer <@ NotNull T , @ NotNull Path > consumer
833+ @ NotNull Path directory ,
834+ @ NotNull T argument ,
835+ @ NotNull BiConsumer <@ NotNull T , @ NotNull Path > consumer
836836 ) {
837837 validateDirectory (directory );
838838
839839 try (var stream = Files .newDirectoryStream (directory )) {
840- for (Path path : stream ) {
840+ for (var path : stream ) {
841841 consumer .accept (argument , path );
842842 }
843843 } catch (IOException e ) {
@@ -855,15 +855,15 @@ public static <T> void forEachR(
855855 * @param <T> the argument's type.
856856 */
857857 public static <T > void forEachR (
858- @ NotNull Path directory ,
859- @ NotNull T argument ,
860- @ NotNull Predicate <@ NotNull Path > condition ,
861- @ NotNull BiConsumer <@ NotNull T , @ NotNull Path > consumer
858+ @ NotNull Path directory ,
859+ @ NotNull T argument ,
860+ @ NotNull Predicate <@ NotNull Path > condition ,
861+ @ NotNull BiConsumer <@ NotNull T , @ NotNull Path > consumer
862862 ) {
863863 validateDirectory (directory );
864864
865865 try (var stream = Files .newDirectoryStream (directory )) {
866- for (Path path : stream ) {
866+ for (var path : stream ) {
867867 if (condition .test (path )) {
868868 consumer .accept (argument , path );
869869 }
0 commit comments