当前位置: 首页>>代码示例>>Java>>正文


Java Emitter类代码示例

本文整理汇总了Java中io.reactivex.Emitter的典型用法代码示例。如果您正苦于以下问题:Java Emitter类的具体用法?Java Emitter怎么用?Java Emitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Emitter类属于io.reactivex包,在下文中一共展示了Emitter类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import io.reactivex.Emitter; //导入依赖的package包/类
private static <T> Flowable<T> create(NamedPreparedStatement ps, List<Object> parameters,
        Function<? super ResultSet, T> mapper) {
    Callable<ResultSet> initialState = () -> {
        Util.convertAndSetParameters(ps.ps, parameters, ps.names);
        ps.ps.execute();
        return ps.ps.getGeneratedKeys();
    };
    BiConsumer<ResultSet, Emitter<T>> generator = (rs, emitter) -> {
        if (rs.next()) {
            emitter.onNext(mapper.apply(rs));
        } else {
            emitter.onComplete();
        }
    };
    Consumer<ResultSet> disposer = Util::closeSilently;
    return Flowable.generate(initialState, generator, disposer);
}
 
开发者ID:davidmoten,项目名称:rxjava2-jdbc,代码行数:18,代码来源:Update.java

示例2: createFlowable

import io.reactivex.Emitter; //导入依赖的package包/类
private static <T> Flowable<T> createFlowable(NamedCallableStatement stmt,
        Function<? super ResultSet, ? extends T> f) throws SQLException {
    ResultSet rsActual = stmt.stmt.getResultSet();
    Callable<ResultSet> initialState = () -> rsActual;
    BiConsumer<ResultSet, Emitter<T>> generator = (rs, emitter) -> {
        log.debug("getting row from ps={}, rs={}", stmt.stmt, rs);
        if (rs.next()) {
            T v = f.apply(rs);
            log.debug("emitting {}", v);
            emitter.onNext(v);
        } else {
            log.debug("completed");
            emitter.onComplete();
        }
    };
    Consumer<ResultSet> disposeState = Util::closeSilently;
    return Flowable.generate(initialState, generator, disposeState);
}
 
开发者ID:davidmoten,项目名称:rxjava2-jdbc,代码行数:19,代码来源:Call.java

示例3: from

import io.reactivex.Emitter; //导入依赖的package包/类
/**
 * Returns a Flowable stream of byte arrays from the given
 * {@link InputStream} between 1 and {@code bufferSize} bytes.
 * 
 * @param is
 *            input stream of bytes
 * @param bufferSize
 *            max emitted byte array size
 * @return a stream of byte arrays
 */
public static Flowable<byte[]> from(final InputStream is, final int bufferSize) {
    return Flowable.generate(new Consumer<Emitter<byte[]>>() {
        @Override
        public void accept(Emitter<byte[]> emitter) throws Exception {
            byte[] buffer = new byte[bufferSize];
            int count = is.read(buffer);
            if (count == -1) {
                emitter.onComplete();
            } else if (count < bufferSize) {
                emitter.onNext(Arrays.copyOf(buffer, count));
            } else {
                emitter.onNext(buffer);
            }
        }
    });
}
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:27,代码来源:Bytes.java

示例4: unzip

import io.reactivex.Emitter; //导入依赖的package包/类
public static Flowable<ZippedEntry> unzip(final ZipInputStream zis) {

        return Flowable.generate(new Consumer<Emitter<ZippedEntry>>() {
            @Override
            public void accept(Emitter<ZippedEntry> emitter) throws IOException {
                ZipEntry zipEntry = zis.getNextEntry();
                if (zipEntry != null) {
                    emitter.onNext(new ZippedEntry(zipEntry, zis));
                } else {
                    // end of stream so eagerly close the stream (might not be a
                    // good idea since this method did not create the zis
                    zis.close();
                    emitter.onComplete();
                }
            }
        });

    }
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:19,代码来源:Bytes.java

示例5: read

import io.reactivex.Emitter; //导入依赖的package包/类
public <T> Flowable<T> read(final Class<T> cls, final Input input) {

            return Flowable.generate(new Consumer<Emitter<T>>() {

                @Override
                public void accept(Emitter<T> emitter) throws Exception {
                    if (input.eof()) {
                        emitter.onComplete();
                    } else {
                        T t = kryo.readObject(input, cls);
                        emitter.onNext(t);
                    }
                }

            });
        }
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:17,代码来源:Serialized.java

示例6: accept

import io.reactivex.Emitter; //导入依赖的package包/类
@Override
public void accept(State state, Emitter<SqsMessage> emitter) throws Exception {
    final Queue<Message> q = state.queue;
    Optional<SqsMessage> next = Optional.empty();
    while (!next.isPresent()) {
        while (q.isEmpty()) {
            final ReceiveMessageResult result = sqs.receiveMessage(request);
            q.addAll(result.getMessages());
        }
        final Message message = q.poll();
        next = getNextMessage(message, queueUrl, bucketName, s3, sqs, service);
    }
    emitter.onNext(next.get());
}
 
开发者ID:davidmoten,项目名称:rxjava2-aws,代码行数:15,代码来源:Sqs.java

示例7: createServerSocketFlowable

import io.reactivex.Emitter; //导入依赖的package包/类
private static Flowable<Flowable<byte[]>> createServerSocketFlowable(final ServerSocket serverSocket,
        final long timeoutMs, final int bufferSize, final Action preAcceptAction,
        final Predicate<? super Socket> acceptSocket) {
    return Flowable.generate( //
            new Consumer<Emitter<Flowable<byte[]>>>() {
                @Override
                public void accept(Emitter<Flowable<byte[]>> emitter) throws Exception {
                    acceptConnection(timeoutMs, bufferSize, serverSocket, emitter, preAcceptAction, acceptSocket);
                }
            });
}
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:12,代码来源:FlowableServerSocket.java

示例8: from

import io.reactivex.Emitter; //导入依赖的package包/类
public static Flowable<String> from(final Reader reader, final int bufferSize) {
    return Flowable.generate(new Consumer<Emitter<String>>() {
        final char[] buffer = new char[bufferSize];

        @Override
        public void accept(Emitter<String> emitter) throws Exception {
            int count = reader.read(buffer);
            if (count == -1) {
                emitter.onComplete();
            } else {
                emitter.onNext(String.valueOf(buffer, 0, count));
            }
        }
    });
}
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:16,代码来源:Strings.java

示例9: create

import io.reactivex.Emitter; //导入依赖的package包/类
private static <T> Flowable<? extends T> create(PreparedStatement ps, List<Object> parameters,
        Function<? super ResultSet, T> mapper, List<String> names, String sql, int fetchSize) {
    log.debug("parameters={}", parameters);
    log.debug("names={}", names);

    Callable<ResultSet> initialState = () -> {
        List<Parameter> params = Util.toParameters(parameters);
        boolean hasCollection = params.stream().anyMatch(x -> x.isCollection());
        final PreparedStatement ps2;
        if (hasCollection) {
            // create a new prepared statement with the collection ? substituted with
            // ?s to match the size of the collection parameter
            ps2 = Util.prepare(ps.getConnection(), fetchSize, sql, params);
            // now wrap the rs to auto close ps2 because it is single use (the next
            // collection parameter may have a different ordinality so we need to build
            // a new PreparedStatement with a different number of question marks
            // substituted
            return new ResultSetAutoClosesStatement(Util //
                    .setParameters(ps2, params, names) //
                    .executeQuery(), ps2);
        } else {
            // use the current prepared statement (normal re-use)
            ps2 = ps;
            return Util //
                    .setParameters(ps2, params, names) //
                    .executeQuery();
        }
    };
    BiConsumer<ResultSet, Emitter<T>> generator = (rs, emitter) -> {
        log.debug("getting row from ps={}, rs={}", rs.getStatement(), rs);
        if (rs.next()) {
            T v = mapper.apply(rs);
            log.debug("emitting {}", v);
            emitter.onNext(v);
        } else {
            log.debug("completed");
            emitter.onComplete();
        }
    };
    Consumer<ResultSet> disposeState = Util::closeSilently;
    return Flowable.generate(initialState, generator, disposeState);
}
 
开发者ID:davidmoten,项目名称:rxjava2-jdbc,代码行数:43,代码来源:Select.java

示例10: ObserverWrapper

import io.reactivex.Emitter; //导入依赖的package包/类
public ObserverWrapper(Emitter<T> emitter) {
    mEmitter = emitter;
}
 
开发者ID:dkhmelenko,项目名称:miband-android,代码行数:4,代码来源:ObserverWrapper.java

示例11: execute

import io.reactivex.Emitter; //导入依赖的package包/类
void execute(Realm realm, Emitter<T> emitter); 
开发者ID:krokers,项目名称:exchange-rates-mvvm,代码行数:2,代码来源:RealmManagerBase.java


注:本文中的io.reactivex.Emitter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。