4141import java .util .Date ;
4242import java .util .Iterator ;
4343import java .util .List ;
44+ import java .util .Objects ;
4445import java .util .zip .CRC32 ;
4546import java .util .zip .CheckedInputStream ;
4647import java .util .zip .Checksum ;
@@ -262,19 +263,15 @@ private static void checkEqualSizes(final File srcFile, final File destFile, fin
262263 /**
263264 * Checks requirements for file copy.
264265 *
265- * @param src the source file
266- * @param dest the destination
266+ * @param source the source file
267+ * @param destination the destination
267268 * @throws FileNotFoundException if the destination does not exist
268269 */
269- private static void checkFileRequirements (final File src , final File dest ) throws FileNotFoundException {
270- if (src == null ) {
271- throw new NullPointerException ("Source must not be null" );
272- }
273- if (dest == null ) {
274- throw new NullPointerException ("Destination must not be null" );
275- }
276- if (!src .exists ()) {
277- throw new FileNotFoundException ("Source '" + src + "' does not exist" );
270+ private static void checkFileRequirements (final File source , final File destination ) throws FileNotFoundException {
271+ Objects .requireNonNull (source , "source" );
272+ Objects .requireNonNull (destination , "target" );
273+ if (!source .exists ()) {
274+ throw new FileNotFoundException ("Source '" + source + "' does not exist" );
278275 }
279276 }
280277
@@ -699,29 +696,25 @@ public static void copyDirectory(final File srcDir, final File destDir,
699696 * If the modification operation fails, no indication is provided.
700697 * </p>
701698 *
702- * @param srcDir an existing directory to copy, must not be {@code null}
703- * @param destDir the directory to place the copy in, must not be {@code null}
699+ * @param sourceDir an existing directory to copy, must not be {@code null}
700+ * @param destinationDir the directory to place the copy in, must not be {@code null}
704701 *
705702 * @throws NullPointerException if source or destination is {@code null}
706703 * @throws IllegalArgumentException if {@code srcDir} or {@code destDir} is not a directory
707704 * @throws IOException if source or destination is invalid
708705 * @throws IOException if an IO error occurs during copying
709706 * @since 1.2
710707 */
711- public static void copyDirectoryToDirectory (final File srcDir , final File destDir ) throws IOException {
712- if (srcDir == null ) {
713- throw new NullPointerException ("Source must not be null" );
714- }
715- if (srcDir .exists () && srcDir .isDirectory () == false ) {
716- throw new IllegalArgumentException ("Source '" + srcDir + "' is not a directory" );
708+ public static void copyDirectoryToDirectory (final File sourceDir , final File destinationDir ) throws IOException {
709+ Objects .requireNonNull (sourceDir , "sourceDir" );
710+ if (sourceDir .exists () && sourceDir .isDirectory () == false ) {
711+ throw new IllegalArgumentException ("Source '" + sourceDir + "' is not a directory" );
717712 }
718- if (destDir == null ) {
719- throw new NullPointerException ("Destination must not be null" );
713+ Objects .requireNonNull (destinationDir , "destinationDir" );
714+ if (destinationDir .exists () && destinationDir .isDirectory () == false ) {
715+ throw new IllegalArgumentException ("Destination '" + destinationDir + "' is not a directory" );
720716 }
721- if (destDir .exists () && destDir .isDirectory () == false ) {
722- throw new IllegalArgumentException ("Destination '" + destDir + "' is not a directory" );
723- }
724- copyDirectory (srcDir , new File (destDir , srcDir .getName ()), true );
717+ copyDirectory (sourceDir , new File (destinationDir , sourceDir .getName ()), true );
725718 }
726719
727720 /**
@@ -867,8 +860,8 @@ public static void copyFileToDirectory(final File srcFile, final File destDir) t
867860 * If the modification operation fails, no indication is provided.
868861 * </p>
869862 *
870- * @param srcFile an existing file to copy, must not be {@code null}
871- * @param destDir the directory to place the copy in, must not be {@code null}
863+ * @param sourceFile an existing file to copy, must not be {@code null}
864+ * @param destinationDir the directory to place the copy in, must not be {@code null}
872865 * @param preserveFileDate true if the file date of the copy
873866 * should be the same as the original
874867 *
@@ -880,16 +873,14 @@ public static void copyFileToDirectory(final File srcFile, final File destDir) t
880873 * @see #copyFile(File, File, boolean)
881874 * @since 1.3
882875 */
883- public static void copyFileToDirectory (final File srcFile , final File destDir , final boolean preserveFileDate )
876+ public static void copyFileToDirectory (final File sourceFile , final File destinationDir , final boolean preserveFileDate )
884877 throws IOException {
885- if (destDir == null ) {
886- throw new NullPointerException ("Destination must not be null" );
887- }
888- if (destDir .exists () && destDir .isDirectory () == false ) {
889- throw new IllegalArgumentException ("Destination '" + destDir + "' is not a directory" );
878+ Objects .requireNonNull (destinationDir , "destinationDir" );
879+ if (destinationDir .exists () && destinationDir .isDirectory () == false ) {
880+ throw new IllegalArgumentException ("Destination '" + destinationDir + "' is not a directory" );
890881 }
891- final File destFile = new File (destDir , srcFile .getName ());
892- copyFile (srcFile , destFile , preserveFileDate );
882+ final File destFile = new File (destinationDir , sourceFile .getName ());
883+ copyFile (sourceFile , destFile , preserveFileDate );
893884 }
894885
895886 /**
@@ -933,8 +924,8 @@ public static void copyInputStreamToFile(final InputStream source, final File de
933924 * If the modification operation fails, no indication is provided.
934925 * </p>
935926 *
936- * @param src an existing file or directory to copy, must not be {@code null}
937- * @param destDir the directory to place the copy in, must not be {@code null}
927+ * @param sourceFile an existing file or directory to copy, must not be {@code null}
928+ * @param destinationDir the directory to place the copy in, must not be {@code null}
938929 *
939930 * @throws NullPointerException if source or destination is {@code null}
940931 * @throws IOException if source or destination is invalid
@@ -943,16 +934,14 @@ public static void copyInputStreamToFile(final InputStream source, final File de
943934 * @see #copyFileToDirectory(File, File)
944935 * @since 2.6
945936 */
946- public static void copyToDirectory (final File src , final File destDir ) throws IOException {
947- if (src == null ) {
948- throw new NullPointerException ("Source must not be null" );
949- }
950- if (src .isFile ()) {
951- copyFileToDirectory (src , destDir );
952- } else if (src .isDirectory ()) {
953- copyDirectoryToDirectory (src , destDir );
937+ public static void copyToDirectory (final File sourceFile , final File destinationDir ) throws IOException {
938+ Objects .requireNonNull (sourceFile , "sourceFile" );
939+ if (sourceFile .isFile ()) {
940+ copyFileToDirectory (sourceFile , destinationDir );
941+ } else if (sourceFile .isDirectory ()) {
942+ copyDirectoryToDirectory (sourceFile , destinationDir );
954943 } else {
955- throw new IOException ("The source " + src + " does not exist" );
944+ throw new IOException ("The source " + sourceFile + " does not exist" );
956945 }
957946 }
958947
@@ -972,21 +961,19 @@ public static void copyToDirectory(final File src, final File destDir) throws IO
972961 * If the modification operation fails, no indication is provided.
973962 * </p>
974963 *
975- * @param srcs a existing files to copy, must not be {@code null}
976- * @param destDir the directory to place the copy in, must not be {@code null}
964+ * @param sourceIterable a existing files to copy, must not be {@code null}
965+ * @param destinationDir the directory to place the copy in, must not be {@code null}
977966 *
978967 * @throws NullPointerException if source or destination is null
979968 * @throws IOException if source or destination is invalid
980969 * @throws IOException if an IO error occurs during copying
981970 * @see #copyFileToDirectory(File, File)
982971 * @since 2.6
983972 */
984- public static void copyToDirectory (final Iterable <File > srcs , final File destDir ) throws IOException {
985- if (srcs == null ) {
986- throw new NullPointerException ("Sources must not be null" );
987- }
988- for (final File src : srcs ) {
989- copyFileToDirectory (src , destDir );
973+ public static void copyToDirectory (final Iterable <File > sourceIterable , final File destinationDir ) throws IOException {
974+ Objects .requireNonNull (sourceIterable , "sourceIterable" );
975+ for (final File src : sourceIterable ) {
976+ copyFileToDirectory (src , destinationDir );
990977 }
991978 }
992979
@@ -1430,12 +1417,8 @@ public static void forceMkdirParent(final File file) throws IOException {
14301417 * @since 2.1
14311418 */
14321419 public static File getFile (final File directory , final String ... names ) {
1433- if (directory == null ) {
1434- throw new NullPointerException ("directory must not be null" );
1435- }
1436- if (names == null ) {
1437- throw new NullPointerException ("names must not be null" );
1438- }
1420+ Objects .requireNonNull (directory , "directory" );
1421+ Objects .requireNonNull (names , "names" );
14391422 File file = directory ;
14401423 for (final String name : names ) {
14411424 file = new File (file , name );
@@ -1451,9 +1434,7 @@ public static File getFile(final File directory, final String... names) {
14511434 * @since 2.1
14521435 */
14531436 public static File getFile (final String ... names ) {
1454- if (names == null ) {
1455- throw new NullPointerException ("names must not be null" );
1456- }
1437+ Objects .requireNonNull (names , "names" );
14571438 File file = null ;
14581439 for (final String name : names ) {
14591440 if (file == null ) {
@@ -1726,9 +1707,7 @@ public static boolean isFileOlder(final File file, final long timeMillis) {
17261707 * @since 2.0
17271708 */
17281709 public static boolean isSymlink (final File file ) {
1729- if (file == null ) {
1730- throw new NullPointerException ("File must not be null" );
1731- }
1710+ Objects .requireNonNull (file , "file" );
17321711 return Files .isSymbolicLink (file .toPath ());
17331712 }
17341713
@@ -2645,9 +2624,7 @@ private static void validateListFilesParameters(final File directory, final IOFi
26452624 if (!directory .isDirectory ()) {
26462625 throw new IllegalArgumentException ("Parameter 'directory' is not a directory: " + directory );
26472626 }
2648- if (fileFilter == null ) {
2649- throw new NullPointerException ("Parameter 'fileFilter' is null" );
2650- }
2627+ Objects .requireNonNull (fileFilter , "fileFilter" );
26512628 }
26522629
26532630 /**
@@ -2658,19 +2635,15 @@ private static void validateListFilesParameters(final File directory, final IOFi
26582635 * <li>Throws {@link FileNotFoundException} if {@code src} does not exist</li>
26592636 * </ul>
26602637 *
2661- * @param src the file or directory to be moved
2662- * @param dest the destination file or directory
2638+ * @param source the file or directory to be moved
2639+ * @param destination the destination file or directory
26632640 * @throws FileNotFoundException if {@code src} file does not exist
26642641 */
2665- private static void validateMoveParameters (final File src , final File dest ) throws FileNotFoundException {
2666- if (src == null ) {
2667- throw new NullPointerException ("Source must not be null" );
2668- }
2669- if (dest == null ) {
2670- throw new NullPointerException ("Destination must not be null" );
2671- }
2672- if (!src .exists ()) {
2673- throw new FileNotFoundException ("Source '" + src + "' does not exist" );
2642+ private static void validateMoveParameters (final File source , final File destination ) throws FileNotFoundException {
2643+ Objects .requireNonNull (source , "source" );
2644+ Objects .requireNonNull (destination , "destination" );
2645+ if (!source .exists ()) {
2646+ throw new FileNotFoundException ("Source '" + source + "' does not exist" );
26742647 }
26752648 }
26762649
0 commit comments