本文整理汇总了Java中rx.observables.SyncOnSubscribe类的典型用法代码示例。如果您正苦于以下问题:Java SyncOnSubscribe类的具体用法?Java SyncOnSubscribe怎么用?Java SyncOnSubscribe使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SyncOnSubscribe类属于rx.observables包,在下文中一共展示了SyncOnSubscribe类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: adapt
import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
@Override
public Observable<T> adapt(final Call<T> call) {
return Observable.<T>create(SyncOnSubscribe.createSingleState(new Func0<Call<T>>() {
@Override
public Call<T> call() {
return call.clone();
}
}, new Action2<Call<T>, Observer<? super T>>() {
@Override
public void call(Call<T> callClone, Observer<? super T> observer) {
try {
observer.onNext(callClone.execute());
observer.onCompleted();
} catch (Throwable throwable) {
observer.onError(throwable);
}
}
}, new Action1<Call<T>>() {
@Override
public void call(Call<T> tCall) {
tCall.cancel();
}
}));
}
示例2: clearCacheFolder
import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
public static Observable<Boolean> clearCacheFolder(final String... paths) {
return Observable
.create(new SyncOnSubscribe<Integer, Boolean>() {
@Override
protected Integer generateState() {
return 1;
}
@Override
protected Integer next(Integer state, Observer<? super Boolean> observer) {
if (state > 0) {
for (String path : paths) {
deleteFolderFile(path, false);
}
observer.onNext(true);
observer.onCompleted();
}
return -1;
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
示例3: createSyncOnSubscribe
import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
@NonNull
private static SyncOnSubscribe<ByteBuffer, byte[]> createSyncOnSubscribe(final byte[] bytes, final int maxBatchSize) {
return SyncOnSubscribe.createSingleState(
new Func0<ByteBuffer>() {
@Override
public ByteBuffer call() {
return ByteBuffer.wrap(bytes);
}
},
new Action2<ByteBuffer, Observer<? super byte[]>>() {
@Override
public void call(ByteBuffer byteBuffer, Observer<? super byte[]> observer) {
int nextBatchSize = Math.min(byteBuffer.remaining(), maxBatchSize);
if (nextBatchSize == 0) {
observer.onCompleted();
return;
}
final byte[] nextBatch = new byte[nextBatchSize];
byteBuffer.get(nextBatch);
observer.onNext(nextBatch);
}
}
);
}
示例4: observable
import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
@Override
public Observable<T> observable() {
return Observable.create(new SyncOnSubscribe<CloseableIterator<T>, T>() {
@Override
protected CloseableIterator<T> generateState() {
try {
return mCallable.call();
} catch (Exception e) {
throw new AlchemyException(e);
}
}
@Override
protected CloseableIterator<T> next(CloseableIterator<T> state, Observer<? super T> observer) {
if (!state.hasNext()) {
observer.onCompleted();
state.close();
return state;
}
observer.onNext(state.next());
return state;
}
});
}
示例5: createServerSocketObservable
import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
private static Observable<Observable<byte[]>> createServerSocketObservable(
ServerSocket serverSocket, final long timeoutMs, final int bufferSize,
final Action0 preAcceptAction, final Func1<? super Socket, Boolean> acceptSocket) {
return Observable.create( //
SyncOnSubscribe.<ServerSocket, Observable<byte[]>> createSingleState( //
Functions.constant0(serverSocket), //
new Action2<ServerSocket, Observer<? super Observable<byte[]>>>() {
@Override
public void call(ServerSocket ss,
Observer<? super Observable<byte[]>> observer) {
acceptConnection(timeoutMs, bufferSize, ss, observer,
preAcceptAction, acceptSocket);
}
}));
}
示例6: read
import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
public <T> Observable<T> read(final Class<T> cls, final Input input, final int bufferSize) {
return Observable.create(new SyncOnSubscribe<Input,T>() {
@Override
protected Input generateState() {
return input;
}
@Override
protected Input next(Input arg0, Observer<? super T> observer) {
if (input.eof()) {
observer.onCompleted();
} else {
T t = kryo.readObject(input, cls);
observer.onNext(t);
}
return input;
}
});
}
示例7: create
import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
@Beta
public static <S, T> Observable<T> create(SyncOnSubscribe<S, T> syncOnSubscribe) {
return new Observable(hook.onCreate(syncOnSubscribe));
}
示例8: create
import rx.observables.SyncOnSubscribe; //导入依赖的package包/类
public static <S, T> ReactiveSeq<T> create(SyncOnSubscribe<S, T> syncOnSubscribe) {
return reactiveSeq(Observable.create(syncOnSubscribe));
}