@Test public void shouldGetCachedResult() throws IOException { final File newFolder = temporaryFolder.newFolder(); CacheUrlAsset cacheUrlAsset = new CacheUrlAsset(new URL("http: CacheUrlAsset.TEMP_LOCATION = newFolder.getAbsolutePath(); final Path path = Paths.get(newFolder.getAbsolutePath(), "arq.txt"); Files.write(path, "Hello".getBytes(StandardCharsets.UTF_8)); InputStream is = cacheUrlAsset.openStream(); String content = slurp(is); assertThat(content, is("Hello")); }
@Override public InputStream openStream() { final URL source = this.getSource(); String fileName = getFileName(source); File file = new File(TEMP_LOCATION, fileName); try { if (!file.exists() || !file.isFile() || isExpired(file)) { InputStream is = super.openStream(); Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } return new BufferedInputStream(new FileInputStream(file), 8192); } catch (IOException e) { throw new RuntimeException(e); } }
CacheUrlAsset extends UrlAsset { @Override public InputStream openStream() { final URL source = this.getSource(); String fileName = getFileName(source); File file = new File(TEMP_LOCATION, fileName); try { if (!file.exists() || !file.isFile() || isExpired(file)) { InputStream is = super.openStream(); Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } return new BufferedInputStream(new FileInputStream(file), 8192); } catch (IOException e) { throw new RuntimeException(e); } } }
CacheUrlAsset extends UrlAsset { @Override public InputStream openStream() { final URL source = this.getSource(); String fileName = getFileName(source); File file = new File(TEMP_LOCATION, fileName); try { if (!file.exists() || !file.isFile() || isExpired(file)) { InputStream is = super.openStream(); Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } return new BufferedInputStream(new FileInputStream(file), 8192); } catch (IOException e) { throw new RuntimeException(e); } } CacheUrlAsset(URL url);  CacheUrlAsset(URL url, long expirationTime, TimeUnit timeUnit); }
CacheUrlAsset extends UrlAsset { @Override public InputStream openStream() { final URL source = this.getSource(); String fileName = getFileName(source); File file = new File(TEMP_LOCATION, fileName); try { if (!file.exists() || !file.isFile() || isExpired(file)) { InputStream is = super.openStream(); Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } return new BufferedInputStream(new FileInputStream(file), 8192); } catch (IOException e) { throw new RuntimeException(e); } } CacheUrlAsset(URL url);  CacheUrlAsset(URL url, long expirationTime, TimeUnit timeUnit); @Override InputStream openStream(); }
CacheUrlAsset extends UrlAsset { @Override public InputStream openStream() { final URL source = this.getSource(); String fileName = getFileName(source); File file = new File(TEMP_LOCATION, fileName); try { if (!file.exists() || !file.isFile() || isExpired(file)) { InputStream is = super.openStream(); Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); } return new BufferedInputStream(new FileInputStream(file), 8192); } catch (IOException e) { throw new RuntimeException(e); } } CacheUrlAsset(URL url);  CacheUrlAsset(URL url, long expirationTime, TimeUnit timeUnit); @Override InputStream openStream();  }