Search in sources :

Example 1 with ByteBufferListParser

use of com.koushikdutta.async.parser.ByteBufferListParser in project ion by koush.

the class BitmapFetcher method execute.

public void execute() {
    final Ion ion = builder.ion;
    // bitmaps that were transformed are put into the FileCache to prevent
    // subsequent retransformation. See if we can retrieve the bitmap from the disk cache.
    // See TransformBitmap for where the cache is populated.
    FileCache fileCache = ion.responseCache.getFileCache();
    if (!builder.noCache && fileCache.exists(bitmapKey) && !deepZoom) {
        BitmapCallback.getBitmapSnapshot(ion, bitmapKey, postProcess);
        return;
    }
    // Perform a download as necessary.
    if (ion.bitmapsPending.tag(decodeKey) == null && !fastLoad(builder.uri)) {
        builder.setHandler(null);
        builder.loadRequestCallback = this;
        if (!deepZoom) {
            Future<Response<ByteBufferList>> emitterTransform = builder.execute(new ByteBufferListParser(), new Runnable() {

                @Override
                public void run() {
                    AsyncServer.post(Ion.mainHandler, new Runnable() {

                        @Override
                        public void run() {
                            ion.bitmapsPending.remove(decodeKey);
                        }
                    });
                }
            }).withResponse();
            emitterTransform.setCallback(new LoadBitmap(ion, decodeKey, !hasTransforms, sampleWidth, sampleHeight, animateGif));
        } else {
            //                System.out.println("downloading file for deepZoom");
            File file = fileCache.getTempFile();
            Future<Response<File>> emitterTransform = builder.write(file).withResponse();
            LoadDeepZoom loadDeepZoom = new LoadDeepZoom(ion, decodeKey, animateGif, fileCache);
            emitterTransform.setCallback(loadDeepZoom);
        }
    }
    executeTransforms(ion);
}
Also used : ByteBufferListParser(com.koushikdutta.async.parser.ByteBufferListParser) File(java.io.File) MediaFile(com.koushikdutta.ion.loader.MediaFile) FileCache(com.koushikdutta.async.util.FileCache)

Aggregations

ByteBufferListParser (com.koushikdutta.async.parser.ByteBufferListParser)1 FileCache (com.koushikdutta.async.util.FileCache)1 MediaFile (com.koushikdutta.ion.loader.MediaFile)1 File (java.io.File)1