@Test public void copyToDirectory() throws Exception { File toDir = temp.newFolder(); File copy = underTest.copyToDirectory(location, toDir); File copy2 = underTest.copyToDirectory(locationWithFilename, toDir); assertThat(copy).exists().isFile(); assertThat(copy2).exists().isFile(); assertThat(copy.getName()).isEqualTo("foo.txt"); assertThat(copy2.getName()).isEqualTo("bar.txt"); assertThat(FileUtils.readFileToString(copy)).isEqualTo("foo"); assertThat(FileUtils.readFileToString(copy2)).isEqualTo("foo"); }
@Override public File copyToDirectory(URLLocation location, File toDir) { try { if (isHttpRequest(location)) { HttpCall httpCall = callHttpRequest(location); return httpCall.downloadToDirectory(toDir); } File toFile = new File(toDir, location.getFileName()); FileUtils.copyURLToFile(location.getURL(), toFile); return toFile; } catch (IOException e) { throw new IllegalStateException(format("Fail to copy %s to directory: %s", location, toDir), e); } }
URLLocator implements Locator<URLLocation> { @Override public File copyToDirectory(URLLocation location, File toDir) { try { if (isHttpRequest(location)) { HttpCall httpCall = callHttpRequest(location); return httpCall.downloadToDirectory(toDir); } File toFile = new File(toDir, location.getFileName()); FileUtils.copyURLToFile(location.getURL(), toFile); return toFile; } catch (IOException e) { throw new IllegalStateException(format("Fail to copy %s to directory: %s", location, toDir), e); } } }
URLLocator implements Locator<URLLocation> { @Override public File copyToDirectory(URLLocation location, File toDir) { try { if (isHttpRequest(location)) { HttpCall httpCall = callHttpRequest(location); return httpCall.downloadToDirectory(toDir); } File toFile = new File(toDir, location.getFileName()); FileUtils.copyURLToFile(location.getURL(), toFile); return toFile; } catch (IOException e) { throw new IllegalStateException(format("Fail to copy %s to directory: %s", location, toDir), e); } }  }
URLLocator implements Locator<URLLocation> { @Override public File copyToDirectory(URLLocation location, File toDir) { try { if (isHttpRequest(location)) { HttpCall httpCall = callHttpRequest(location); return httpCall.downloadToDirectory(toDir); } File toFile = new File(toDir, location.getFileName()); FileUtils.copyURLToFile(location.getURL(), toFile); return toFile; } catch (IOException e) { throw new IllegalStateException(format("Fail to copy %s to directory: %s", location, toDir), e); } }  @Override File locate(URLLocation location); @Override File copyToDirectory(URLLocation location, File toDir); @Override InputStream openInputStream(URLLocation location); @Override File copyToFile(URLLocation location, File toFile); }
URLLocator implements Locator<URLLocation> { @Override public File copyToDirectory(URLLocation location, File toDir) { try { if (isHttpRequest(location)) { HttpCall httpCall = callHttpRequest(location); return httpCall.downloadToDirectory(toDir); } File toFile = new File(toDir, location.getFileName()); FileUtils.copyURLToFile(location.getURL(), toFile); return toFile; } catch (IOException e) { throw new IllegalStateException(format("Fail to copy %s to directory: %s", location, toDir), e); } }  @Override File locate(URLLocation location); @Override File copyToDirectory(URLLocation location, File toDir); @Override InputStream openInputStream(URLLocation location); @Override File copyToFile(URLLocation location, File toFile);  }