Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.koushikdutta.ion.loader;
 
 import  android.net.Uri;
 
Created by koush on 5/22/13.
public class FileLoader implements Loader {
    private static final class FileFuture extends SimpleFuture<DataEmitter> {
    }
    @Override
    public Future<BitmapInfoloadBitmap(Ion ionfinal String uri) {
        return null;
    }
    @Override
    public Future<InputStreamload(final Ion ionfinal AsyncHttpRequest request) {
        if (!request.getUri().getScheme().startsWith("file"))
            return null;
        final SimpleFuture<InputStreamret = new SimpleFuture<InputStream>();
        ion.getServer().getExecutorService().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    InputStream stream = new FileInputStream(new File(request.getUri()));
                    ret.setComplete(stream);
                }
                catch (Exception e) {
                    ret.setComplete(e);
                }
            }
        });
        return ret;
    }
    @Override
    public Future<DataEmitterload(final Ion ionfinal AsyncHttpRequest requestfinal FutureCallback<LoaderEmittercallback) {
        if (!request.getUri().getScheme().startsWith("file"))
            return null;
        final FileFuture ret = new FileFuture();
        ion.getHttpClient().getServer().post(new Runnable() {
            @Override
            public void run() {
                File file = new File(request.getUri());
                FileDataEmitter emitter = new FileDataEmitter(ion.getHttpClient().getServer(), file);
                ret.setComplete(emitter);
                callback.onCompleted(nullnew LoaderEmitter(emitter, (int)file.length(), .nullnull));
            }
        });
        return ret;
    }
New to GrepCode? Check out our FAQ X