@Test public void testRemove() { PropertiesBasedResumableProcessor propertiesProcessor = new PropertiesBasedResumableProcessor(); propertiesProcessor.put("http://localhost/test.url", 15L); propertiesProcessor.put("http://localhost/test2.url", 50L); propertiesProcessor.remove("http://localhost/test.url"); propertiesProcessor.save(null); propertiesProcessor = new PropertiesBasedResumableProcessor(); Map<String, Long> propertiesMap = propertiesProcessor.load(); assertEquals(propertiesMap.size(), 1); assertEquals(propertiesMap.get("http://localhost/test2.url"), Long.valueOf(50L)); } }
public ResumableAsyncHandler(AsyncHandler<Response> decoratedAsyncHandler) { this(0, new PropertiesBasedResumableProcessor(), decoratedAsyncHandler, false); }
/** * {@inheritDoc} */ @Override public void save(Map<String, Long> map) { log.debug("Saving current download state {}", properties.toString()); OutputStream os = null; try { if (!TMP.exists() && !TMP.mkdirs()) { throw new IllegalStateException("Unable to create directory: " + TMP.getAbsolutePath()); } File f = new File(TMP, storeName); if (!f.exists() && !f.createNewFile()) { throw new IllegalStateException("Unable to create temp file: " + f.getAbsolutePath()); } if (!f.canWrite()) { throw new IllegalStateException(); } os = Files.newOutputStream(f.toPath()); for (Map.Entry<String, Long> e : properties.entrySet()) { os.write(append(e).getBytes(UTF_8)); } os.flush(); } catch (Throwable e) { log.warn(e.getMessage(), e); } finally { closeSilently(os); } }
public ResumableAsyncHandler(long byteTransferred, AsyncHandler<Response> decoratedAsyncHandler) { this(byteTransferred, new PropertiesBasedResumableProcessor(), decoratedAsyncHandler, false); }
/** * {@inheritDoc} */ @Override public void save(Map<String, Long> map) { log.debug("Saving current download state {}", properties.toString()); FileOutputStream os = null; try { if (!TMP.exists() && !TMP.mkdirs()) { throw new IllegalStateException("Unable to create directory: " + TMP.getAbsolutePath()); } File f = new File(TMP, storeName); if (!f.exists() && !f.createNewFile()) { throw new IllegalStateException("Unable to create temp file: " + f.getAbsolutePath()); } if (!f.canWrite()) { throw new IllegalStateException(); } os = new FileOutputStream(f); for (Map.Entry<String, Long> e : properties.entrySet()) { os.write(append(e).getBytes(UTF_8)); } os.flush(); } catch (Throwable e) { log.warn(e.getMessage(), e); } finally { if (os != null) closeSilently(os); } }
@Test public void testSaveLoad() { PropertiesBasedResumableProcessor p = new PropertiesBasedResumableProcessor(); p.put("http://localhost/test.url", 15L); p.put("http://localhost/test2.url", 50L); p.save(null); p = new PropertiesBasedResumableProcessor(); Map<String, Long> m = p.load(); assertEquals(m.size(), 2); assertEquals(m.get("http://localhost/test.url"), Long.valueOf(15L)); assertEquals(m.get("http://localhost/test2.url"), Long.valueOf(50L)); }
public ResumableAsyncHandler(long byteTransferred, AsyncHandler<Response> decoratedAsyncHandler) { this(byteTransferred, new PropertiesBasedResumableProcessor(), decoratedAsyncHandler, false); }
public ResumableAsyncHandler(AsyncHandler<Response> decoratedAsyncHandler) { this(0, new PropertiesBasedResumableProcessor(), decoratedAsyncHandler, false); }