Ejemplo n.º 1
0
 /** Pulls bitmap from diskcache */
 private @Nullable ParcelFileDescriptor createPipe(final ArtInfo artInfo) {
   final byte[] bytes = mL2Cache.getBytes(artInfo.cacheKey());
   if (bytes == null) {
     return null;
   }
   try {
     final ParcelFileDescriptor[] pipe = ParcelFileDescriptor.createPipe();
     final OutputStream out = new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]);
     final ParcelFileDescriptor in = pipe[0];
     final Scheduler.Worker worker = mScheduler.createWorker();
     worker.schedule(
         new Action0() {
           @Override
           public void call() {
             try {
               IOUtils.write(bytes, out);
               out.flush();
             } catch (IOException e) {
               Timber.w("createPipe(e=%s) for %s", e.getMessage(), artInfo);
             } finally {
               IOUtils.closeQuietly(out);
               worker.unsubscribe();
             }
           }
         });
     return in;
   } catch (IOException e) {
     Timber.e(e, "createPipe() for %s", artInfo);
     return null;
   }
 }
Ejemplo n.º 2
0
 @Override
 @DebugLog
 public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
   if (!"r".equals(mode)) {
     throw new FileNotFoundException("Provider is read only");
   }
   switch (mUriMatcher.match(uri)) {
     case ArtworkUris.MATCH.ARTINFO:
       {
         final ArtInfo artInfo = ArtInfo.fromUri(uri);
         final ParcelFileDescriptor pfd = getArtwork(artInfo);
         if (pfd != null) {
           return pfd;
         }
         break;
       }
   }
   throw new FileNotFoundException("Could not obtain image from cache or network");
 }