Esempio n. 1
0
 public void actionPerformed(ActionEvent evt) {
   if (adapter != null) {
     try {
       byte[] d;
       InputStream is;
       if (storageFile != null) {
         d = new byte[Storage.getInstance().entrySize(storageFile + IMAGE_SUFFIX)];
         is = Storage.getInstance().createInputStream(storageFile + IMAGE_SUFFIX);
       } else {
         d =
             new byte
                 [(int)
                     FileSystemStorage.getInstance().getLength(fileSystemFile + IMAGE_SUFFIX)];
         is = FileSystemStorage.getInstance().openInputStream(fileSystemFile + IMAGE_SUFFIX);
       }
       Util.readFully(is, d);
       EncodedImage img = EncodedImage.create(d);
       EncodedImage adapted;
       if (adapter.isAsyncAdapter()) {
         adapt = img;
         Display.getInstance().invokeAndBlock(this);
         adapted = adaptedIns;
         adaptedIns = null;
         adapt = null;
       } else {
         adapted = adapter.adaptImage(img, placeholder);
       }
       if (storageFile != null) {
         OutputStream o = Storage.getInstance().createOutputStream(storageFile);
         o.write(adapted.getImageData());
         o.close();
         Storage.getInstance().deleteStorageFile(storageFile + IMAGE_SUFFIX);
       } else {
         OutputStream o = FileSystemStorage.getInstance().openOutputStream(fileSystemFile);
         o.write(adapted.getImageData());
         o.close();
         FileSystemStorage.getInstance().delete(fileSystemFile + IMAGE_SUFFIX);
       }
     } catch (IOException ex) {
       ex.printStackTrace();
       return;
     }
   }
   fetching = false;
   // invoke fetch again to load the local files
   fetch();
 }
Esempio n. 2
0
 /** {@inheritDoc} */
 public byte[] getImageData() {
   if (imageData != null) {
     return imageData;
   }
   return placeholder.getImageData();
 }