Skip to content

Commit 0d41d2f

Browse files
committed
[IO-870] PathUtils.copyFileToDirectory() across file systems
Simplify
1 parent a924140 commit 0d41d2f

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ The <action> type attribute can be add,update,fix,remove.
6565
<action dev="ggregory" type="fix" due-to="Gary Gregory">FileChannels.contentEquals(FileChannel, FileChannel, int) can return false when comparing a non-blocking channel.</action>
6666
<action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate FileChannels.contentEquals(FileChannel, FileChannel, int) in favor of FileChannels.contentEquals(SeekableByteChannel, SeekableByteChannel, int).</action>
6767
<action dev="ggregory" type="fix" due-to="Gary Gregory">Improve performance of IOUtils.contentEquals(InputStream, InputStream) by about 13%.</action>
68+
<action dev="ggregory" type="fix" issue="IO-870" due-to="Gary Gregory">PathUtils.copyFileToDirectory() across file systems #728.</action>
6869
<!-- ADD -->
6970
<action dev="ggregory" type="add" issue="IO-860" due-to="Nico Strecker, Gary Gregory">Add ThrottledInputStream.Builder.setMaxBytes(long, ChronoUnit).</action>
7071
<action dev="ggregory" type="add" due-to="Gary Gregory">Add IOIterable.</action>

src/main/java/org/apache/commons/io/file/PathUtils.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,10 @@ public static Path copyFile(final URL sourceFile, final Path targetFile, final C
320320
* @throws IOException if an I/O error occurs.
321321
* @see Files#copy(Path, Path, CopyOption...)
322322
*/
323+
@SuppressWarnings("resource") // getFileSystem() is a getter
323324
public static Path copyFileToDirectory(final Path sourceFile, final Path targetDirectory, final CopyOption... copyOptions) throws IOException {
324325
// Path.resolve() naturally won't work across FileSystem unless we convert to a String
325-
final Path sourceFileName = sourceFile.getFileName();
326-
if (sourceFileName == null) {
327-
throw new IllegalArgumentException("must have a file name: " + sourceFile);
328-
}
326+
final Path sourceFileName = Objects.requireNonNull(sourceFile.getFileName(), "source file name");
329327
final Path targetFile;
330328
if (sourceFileName.getFileSystem() == targetDirectory.getFileSystem()) {
331329
targetFile = targetDirectory.resolve(sourceFileName);

0 commit comments

Comments
 (0)