use of com.koushikdutta.async.FileDataEmitter in project AndroidAsync by koush.
the class FileTests method testFileDataEmitter.
public void testFileDataEmitter() throws Exception {
final Semaphore semaphore = new Semaphore(0);
File f = getContext().getFileStreamPath("test.txt");
StreamUtility.writeFile(f, "hello world");
FileDataEmitter fdm = new FileDataEmitter(AsyncServer.getDefault(), f);
final Md5 md5 = Md5.createInstance();
Future<String> stringBody = new StringParser().parse(fdm).setCallback(new FutureCallback<String>() {
@Override
public void onCompleted(Exception e, String result) {
semaphore.release();
}
});
fdm.resume();
assertTrue("timeout", semaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS));
assertEquals("hello world", stringBody.get());
}
use of com.koushikdutta.async.FileDataEmitter in project ion by koush.
the class FileLoader method load.
@Override
public Future<DataEmitter> load(final Ion ion, final AsyncHttpRequest request, final FutureCallback<LoaderEmitter> callback) {
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(URI.create(request.getUri().toString()));
FileDataEmitter emitter = new FileDataEmitter(ion.getHttpClient().getServer(), file);
ret.setComplete(emitter);
callback.onCompleted(null, new LoaderEmitter(emitter, (int) file.length(), ResponseServedFrom.LOADED_FROM_CACHE, null, request));
}
});
return ret;
}
Aggregations