@Test public void readAndSave_cacheFileDoesExist() throws MalformedURLException, IOException { final File cache = new File(folder.getRoot(), "test.cache"); cache.createNewFile(); assertThat(cache.exists()).isTrue(); UpdateOperationWithCacheFileTask.readAndSave(cache, new TestXmlDataStore()); assertThat(cache.length() >= 722015).isTrue(); UpdateOperationWithCacheFileTask.readAndSave(cache, new TestXmlDataStore()); assertThat(cache.length() >= 722015).isTrue(); }
protected static void readAndSave(@Nonnull final File file, @Nonnull final DataStore store) throws IOException { Check.notNull(file, "file"); Check.notNull(store, "store"); final URL url = store.getDataUrl(); final Charset charset = store.getCharset(); final boolean isEqual = url.toExternalForm().equals(UrlUtil.toUrl(file).toExternalForm()); if (!isEqual) { final String data = UrlUtil.read(url, charset); if (Data.EMPTY.equals(store.getDataReader().read(data))) { throw new IllegalStateException("The read in content can not be transformed to an instance of 'Data'."); } final File tempFile = createTemporaryFile(file); FileOutputStream outputStream = null; boolean threw = true; try { outputStream = new FileOutputStream(tempFile); outputStream.write(data.getBytes(charset)); deleteFile(file); threw = false; } finally { Closeables.close(outputStream, threw); } renameFile(tempFile, file); } else { LOG.debug(MSG_SAME_RESOURCES); } }
UpdateOperationWithCacheFileTask extends AbstractUpdateOperation { protected static void readAndSave(@Nonnull final File file, @Nonnull final DataStore store) throws IOException { Check.notNull(file, "file"); Check.notNull(store, "store"); final URL url = store.getDataUrl(); final Charset charset = store.getCharset(); final boolean isEqual = url.toExternalForm().equals(UrlUtil.toUrl(file).toExternalForm()); if (!isEqual) { final String data = UrlUtil.read(url, charset); if (Data.EMPTY.equals(store.getDataReader().read(data))) { throw new IllegalStateException("The read in content can not be transformed to an instance of 'Data'."); } final File tempFile = createTemporaryFile(file); FileOutputStream outputStream = null; boolean threw = true; try { outputStream = new FileOutputStream(tempFile); outputStream.write(data.getBytes(charset)); deleteFile(file); threw = false; } finally { Closeables.close(outputStream, threw); } renameFile(tempFile, file); } else { LOG.debug(MSG_SAME_RESOURCES); } } }
UpdateOperationWithCacheFileTask extends AbstractUpdateOperation { protected static void readAndSave(@Nonnull final File file, @Nonnull final DataStore store) throws IOException { Check.notNull(file, "file"); Check.notNull(store, "store"); final URL url = store.getDataUrl(); final Charset charset = store.getCharset(); final boolean isEqual = url.toExternalForm().equals(UrlUtil.toUrl(file).toExternalForm()); if (!isEqual) { final String data = UrlUtil.read(url, charset); if (Data.EMPTY.equals(store.getDataReader().read(data))) { throw new IllegalStateException("The read in content can not be transformed to an instance of 'Data'."); } final File tempFile = createTemporaryFile(file); FileOutputStream outputStream = null; boolean threw = true; try { outputStream = new FileOutputStream(tempFile); outputStream.write(data.getBytes(charset)); deleteFile(file); threw = false; } finally { Closeables.close(outputStream, threw); } renameFile(tempFile, file); } else { LOG.debug(MSG_SAME_RESOURCES); } } UpdateOperationWithCacheFileTask(@Nonnull final AbstractRefreshableDataStore dataStore, @Nonnull final File cacheFile); }
UpdateOperationWithCacheFileTask extends AbstractUpdateOperation { protected static void readAndSave(@Nonnull final File file, @Nonnull final DataStore store) throws IOException { Check.notNull(file, "file"); Check.notNull(store, "store"); final URL url = store.getDataUrl(); final Charset charset = store.getCharset(); final boolean isEqual = url.toExternalForm().equals(UrlUtil.toUrl(file).toExternalForm()); if (!isEqual) { final String data = UrlUtil.read(url, charset); if (Data.EMPTY.equals(store.getDataReader().read(data))) { throw new IllegalStateException("The read in content can not be transformed to an instance of 'Data'."); } final File tempFile = createTemporaryFile(file); FileOutputStream outputStream = null; boolean threw = true; try { outputStream = new FileOutputStream(tempFile); outputStream.write(data.getBytes(charset)); deleteFile(file); threw = false; } finally { Closeables.close(outputStream, threw); } renameFile(tempFile, file); } else { LOG.debug(MSG_SAME_RESOURCES); } } UpdateOperationWithCacheFileTask(@Nonnull final AbstractRefreshableDataStore dataStore, @Nonnull final File cacheFile); @Override void call(); }
UpdateOperationWithCacheFileTask extends AbstractUpdateOperation { protected static void readAndSave(@Nonnull final File file, @Nonnull final DataStore store) throws IOException { Check.notNull(file, "file"); Check.notNull(store, "store"); final URL url = store.getDataUrl(); final Charset charset = store.getCharset(); final boolean isEqual = url.toExternalForm().equals(UrlUtil.toUrl(file).toExternalForm()); if (!isEqual) { final String data = UrlUtil.read(url, charset); if (Data.EMPTY.equals(store.getDataReader().read(data))) { throw new IllegalStateException("The read in content can not be transformed to an instance of 'Data'."); } final File tempFile = createTemporaryFile(file); FileOutputStream outputStream = null; boolean threw = true; try { outputStream = new FileOutputStream(tempFile); outputStream.write(data.getBytes(charset)); deleteFile(file); threw = false; } finally { Closeables.close(outputStream, threw); } renameFile(tempFile, file); } else { LOG.debug(MSG_SAME_RESOURCES); } } UpdateOperationWithCacheFileTask(@Nonnull final AbstractRefreshableDataStore dataStore, @Nonnull final File cacheFile); @Override void call();  }