MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / downloadUrlTo

Method downloadUrlTo

CodenameOne/src/com/codename1/io/Util.java:2285–2326  ·  view source on GitHub ↗
(String url, String fileName, boolean showProgress, boolean background, boolean storage, ActionListener callback)

Source from the content-addressed store, hash-verified

2283 }
2284
2285 private static boolean downloadUrlTo(String url, String fileName, boolean showProgress, boolean background, boolean storage, ActionListener callback) {
2286 ConnectionRequest cr = new ConnectionRequest();
2287 cr.setPost(false);
2288 cr.setFailSilently(true);
2289 cr.setReadResponseForErrors(false);
2290 cr.setDuplicateSupported(true);
2291 cr.setUrl(url);
2292 if (callback != null) {
2293 cr.addResponseListener(callback);
2294 }
2295 if (storage) {
2296 cr.setDestinationStorage(fileName);
2297 } else {
2298 cr.setDestinationFile(fileName);
2299 }
2300 if (background) {
2301 NetworkManager.getInstance().addToQueue(cr);
2302 return true;
2303 }
2304 if (showProgress) {
2305 InfiniteProgress ip = new InfiniteProgress();
2306 Dialog d = ip.showInifiniteBlocking();
2307 NetworkManager.getInstance().addToQueueAndWait(cr);
2308 d.dispose();
2309 } else {
2310 NetworkManager.getInstance().addToQueueAndWait(cr);
2311 }
2312 if (cr.getContentLength() > 0) {
2313 // verify the resulting file has the same size as the content length
2314 if (storage) {
2315 if (Storage.getInstance().entrySize(fileName) < cr.getContentLength()) {
2316 return false;
2317 }
2318 } else {
2319 if (FileSystemStorage.getInstance().getLength(fileName) < cr.getContentLength()) {
2320 return false;
2321 }
2322 }
2323 }
2324 int rc = cr.getResponseCode();
2325 return rc == 200 || rc == 201;
2326 }
2327
2328 /// Shorthand method for Thread sleep that doesn't throw the stupid interrupted checked exception
2329 ///

Calls 15

setPostMethod · 0.95
setFailSilentlyMethod · 0.95
setDuplicateSupportedMethod · 0.95
setUrlMethod · 0.95
addResponseListenerMethod · 0.95
setDestinationStorageMethod · 0.95
setDestinationFileMethod · 0.95
getInstanceMethod · 0.95
showInifiniteBlockingMethod · 0.95
disposeMethod · 0.95
getContentLengthMethod · 0.95

Tested by

no test coverage detected