OpearPackageMojo extends AbstractCommonMojo { static Result<Map<URL, String>> copyUrlStreams(final @NotNull File toDir, final @NotNull List<URL> urls) { final List<URL> dedupedUrls = new ArrayList<>(new LinkedHashSet<>(urls)); final Map<String, URL> renamed = mapDestFileNames(new LinkedHashMap<>(), dedupedUrls, url -> Text.getName(url.getPath())); final Result<List<String>> filenameResults = renamed.entrySet().stream().map(result1(entry -> { try (InputStream is = entry.getValue().openStream()) { FileIOUtils.copyInputStreamToFile(is, new File(toDir, entry.getKey())); return entry.getKey(); } })).collect(Result.tryCollect(Collectors.toList())); return filenameResults.map(filenames -> filenames.stream() .map(zipValuesWithKeyFunc(renamed::get)) .collect(entriesToMap((v1, v2) -> v1))); }  @Override void execute(); static final String OPEAR; }
@Test public void testCopyUrlStreams() throws Exception { final File testOutDir = new File(testOutBaseDir, "testCopyUrlStreams"); FileUtils.deleteDirectory(testOutDir); testOutDir.mkdirs(); final File copyMe1 = new File(srcDir, "copyme.txt"); final File copyMe2 = new File(srcDir, "sub1/copyme.txt"); final Result<Map<URL, String>> result = OpearPackageMojo.copyUrlStreams(testOutDir, Stream.of(copyMe1, copyMe2) .map(Fun.compose1(File::toURI, Fun.uncheck1(URI::toURL))) .collect(Collectors.toList())).teeLogError(); assertTrue("result is successful: " + result.getError(), result.isSuccess()); assertEquals("same values", Stream.of("copyme.txt", "copyme_1.txt") .collect(Collectors.toSet()), new HashSet<>(result.getOrDefault(Collections.emptyMap()).values())); }