use of com.koushikdutta.async.stream.FileDataSink in project ion by koush.
the class FileCacheStore method put.
private <T> Future<T> put(final T value, final AsyncParser<T> parser) {
final SimpleFuture<T> ret = new SimpleFuture<T>();
Ion.getIoExecutorService().execute(new Runnable() {
@Override
public void run() {
final String key = computeKey();
final File file = cache.getTempFile();
final FileDataSink sink = new FileDataSink(ion.getServer(), file);
parser.write(sink, value, new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
sink.end();
if (ex != null) {
file.delete();
ret.setComplete(ex);
return;
}
cache.commitTempFiles(key, file);
ret.setComplete(value);
}
});
}
});
return ret;
}
Aggregations