ResourceLocator implements Locator<ResourceLocation> { @Override public File copyToFile(ResourceLocation location, File toFile) { try (InputStream input = ResourceLocator.class.getResourceAsStream(location.getPath()); OutputStream output = new FileOutputStream(toFile, false)) { IOUtils.copyLarge(input, output); return toFile; } catch (IOException e) { throw new IllegalStateException("Fail to copy " + location + " to file: " + toFile, e); } }  @Override File locate(ResourceLocation location); @Override File copyToDirectory(ResourceLocation location, File toDir); @Override InputStream openInputStream(ResourceLocation location); @Override File copyToFile(ResourceLocation location, File toFile);  }
@Test public void copyToFile() throws Exception { File toFile = temp.newFile(); ResourceLocation location = ResourceLocation.create("/com/sonar/orchestrator/locator/ResourceLocatorTest/foo.txt"); File copy = resourceLocator.copyToFile(location, toFile); assertThat(copy).exists().isFile(); assertThat(copy).isSameAs(toFile); assertThat(FileUtils.readFileToString(copy)).isEqualTo("foo"); }