|
33 | 33 | import java.io.OutputStream; |
34 | 34 | import java.net.URI; |
35 | 35 | import java.net.URISyntaxException; |
| 36 | +import java.net.URL; |
36 | 37 | import java.nio.charset.StandardCharsets; |
37 | 38 | import java.nio.file.DirectoryStream; |
38 | 39 | import java.nio.file.FileAlreadyExistsException; |
|
51 | 52 | import java.util.Map; |
52 | 53 |
|
53 | 54 | import org.apache.commons.io.FileUtils; |
| 55 | +import org.apache.commons.io.FilenameUtils; |
54 | 56 | import org.apache.commons.io.filefilter.NameFileFilter; |
55 | 57 | import org.apache.commons.io.test.TestUtils; |
56 | 58 | import org.apache.commons.lang3.ArrayUtils; |
@@ -154,8 +156,7 @@ public void testCopyDirectoryForDifferentFilesystemsWithAbsolutePathReverse() th |
154 | 156 | @Test |
155 | 157 | public void testCopyDirectoryForDifferentFilesystemsWithRelativePath() throws IOException { |
156 | 158 | final Path archivePath = Paths.get(TEST_JAR_PATH); |
157 | | - try (FileSystem archive = openArchive(archivePath, false); |
158 | | - final FileSystem targetArchive = openArchive(tempDirPath.resolve(TEST_JAR_NAME), true)) { |
| 159 | + try (FileSystem archive = openArchive(archivePath, false); final FileSystem targetArchive = openArchive(tempDirPath.resolve(TEST_JAR_NAME), true)) { |
159 | 160 | final Path targetDir = targetArchive.getPath("targetDir"); |
160 | 161 | Files.createDirectory(targetDir); |
161 | 162 | // relative jar -> relative dir |
@@ -195,6 +196,15 @@ public void testCopyFile() throws IOException { |
195 | 196 | assertEquals(Files.size(sourceFile), Files.size(targetFile)); |
196 | 197 | } |
197 | 198 |
|
| 199 | + @Test |
| 200 | + public void testCopyURL() throws IOException { |
| 201 | + final Path sourceFile = Paths.get("src/test/resources/org/apache/commons/io/dirs-1-file-size-1/file-size-1.bin"); |
| 202 | + final URL url = new URL("file:///" + FilenameUtils.getPath(sourceFile.toAbsolutePath().toString()) + sourceFile.getFileName()); |
| 203 | + final Path targetFile = PathUtils.copyFileToDirectory(url, tempDirPath); |
| 204 | + assertTrue(Files.exists(targetFile)); |
| 205 | + assertEquals(Files.size(sourceFile), Files.size(targetFile)); |
| 206 | + } |
| 207 | + |
198 | 208 | @Test |
199 | 209 | public void testCreateDirectoriesAlreadyExists() throws IOException { |
200 | 210 | assertEquals(tempDirPath.getParent(), PathUtils.createParentDirectories(tempDirPath)); |
@@ -476,7 +486,7 @@ public void testTouch() throws IOException { |
476 | 486 | } |
477 | 487 | assertEquals(1, Files.size(file), "Wrote one byte to file"); |
478 | 488 | final long y2k = new GregorianCalendar(2000, 0, 1).getTime().getTime(); |
479 | | - setLastModifiedMillis(file, y2k); // 0L fails on Win98 |
| 489 | + setLastModifiedMillis(file, y2k); // 0L fails on Win98 |
480 | 490 | assertEquals(y2k, getLastModifiedMillis(file), "Bad test: set lastModified set incorrect value"); |
481 | 491 | final long nowMillis = System.currentTimeMillis(); |
482 | 492 | PathUtils.touch(file); |
|
0 commit comments