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

Method fetch

CodenameOne/src/com/codename1/ui/URLImage.java:563–730  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

561 /// means that the image will be added to the queue right away but probably won't be
562 /// available by the time the method completes.
563 public void fetch() {
564 if (fetching || imageData != null) {
565 return;
566 }
567 fetching = true;
568 try {
569 locked = super.isLocked();
570 if (storageFile != null) {
571 if (Storage.getInstance().exists(storageFile)) {
572 super.unlock();
573 imageData = new byte[Storage.getInstance().entrySize(storageFile)];
574 InputStream is = null; //NOPMD CloseResource
575 try {
576 is = Storage.getInstance().createInputStream(storageFile);
577 Util.readFully(is, imageData);
578 } finally {
579 Util.cleanup(is);
580 }
581 resetCache();
582 fetching = false;
583 repaintImage = true;
584 fireChangedEvent();
585 return;
586 }
587 if (adapter != null) {
588 if (url.startsWith("http://") || url.startsWith("https://")) {
589 SuccessCallback<Image> downloadCb = new SuccessCallback<Image>() {
590 @Override
591 public void onSucess(final Image value) {
592 imageLoader.run(new Runnable() {
593 @Override
594 public void run() {
595 runAndWait(new Runnable() {
596 @Override
597 public void run() {
598 DownloadCompleted onComplete = new DownloadCompleted();
599 onComplete.setSourceImage(value);
600 onComplete.actionPerformed(new ActionEvent(value));
601 }
602 });
603 }
604 });
605 }
606 };
607 if (hasRequestDecorator()) {
608 downloadDecorated(url, storageFile + IMAGE_SUFFIX, downloadCb);
609 } else {
610 Util.downloadImageToStorage(url, storageFile + IMAGE_SUFFIX, downloadCb);
611 }
612 } else {
613 // from file
614 loadImageFromLocalUrl(storageFile + IMAGE_SUFFIX, false);
615 }
616 } else {
617 if (url.startsWith("http://") || url.startsWith("https://")) {
618 SuccessCallback<Image> downloadCb = new SuccessCallback<Image>() {
619 @Override
620 public void onSucess(final Image value) {

Callers 5

getInternalMethod · 0.95
startMethod · 0.95
testDownloadCompletedMethod · 0.95
actionPerformedMethod · 0.45

Calls 15

getInstanceMethod · 0.95
readFullyMethod · 0.95
cleanupMethod · 0.95
hasRequestDecoratorMethod · 0.95
downloadDecoratedMethod · 0.95
loadImageFromLocalUrlMethod · 0.95
getInstanceMethod · 0.95
createInputStreamMethod · 0.80
fireChangedEventMethod · 0.80
existsMethod · 0.65

Tested by 2

testDownloadCompletedMethod · 0.76