@Test public void copyToDir_gets_filename_from_http_header() throws Exception { File toDir = temp.newFolder(); webServer.enqueue(new MockResponse().setBody("hello world").setHeader("Content-Disposition", "attachment; filename=\"foo.txt\"")); underTest.copyToDirectory(URLLocation.create(webServer.url("/bar.txt").url()), toDir); File toFile = new File(toDir, "foo.txt"); assertThat(toFile).exists().isFile().hasContent("hello world"); }
@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);  }