本文整理了Java中reactor.core.publisher.Mono.map()
方法的一些代码示例,展示了Mono.map()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.map()
方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:map
[英]Transform the item emitted by this Mono by applying a synchronous function to it.
[中]通过对其应用同步函数来转换此Mono发出的项。
代码示例来源:origin: spring-projects/spring-security
public final Mono<AbstractAuthenticationToken> convert(Jwt jwt) {
return Mono.just(jwt).map(this.delegate::convert);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public RouterFunctions.Builder after(
BiFunction<ServerRequest, ServerResponse, ServerResponse> responseProcessor) {
Assert.notNull(responseProcessor, "ResponseProcessor must not be null");
return filter((request, next) -> next.handle(request)
.map(serverResponse -> responseProcessor.apply(request, serverResponse)));
}
代码示例来源:origin: spring-projects/spring-security
@Override
@SuppressWarnings("unchecked")
public <T extends OAuth2AuthorizedClient> Mono<T> loadAuthorizedClient(String clientRegistrationId, Authentication principal,
ServerWebExchange exchange) {
Assert.hasText(clientRegistrationId, "clientRegistrationId cannot be empty");
Assert.notNull(exchange, "exchange cannot be null");
return exchange.getSession()
.map(this::getAuthorizedClients)
.flatMap(clients -> Mono.justOrEmpty((T) clients.get(clientRegistrationId)));
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Get multiple values in one batch.
*
* @param keys must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/mget">Redis Documentation: MGET</a>
*/
default Mono<List<ByteBuffer>> mGet(List<ByteBuffer> keys) {
Assert.notNull(keys, "Keys must not be null!");
return mGet(Mono.just(keys)).next().map(MultiValueResponse::getOutput);
}
代码示例来源:origin: codecentric/spring-boot-admin
/**
* Register instance.
*
* @param registration instance to be registered.
* @return the if of the registered instance.
*/
public Mono<InstanceId> register(Registration registration) {
Assert.notNull(registration, "'registration' must not be null");
InstanceId id = generator.generateId(registration);
Assert.notNull(id, "'id' must not be null");
return repository.compute(id, (key, instance) -> {
if (instance == null) {
instance = Instance.create(key);
}
return Mono.just(instance.register(registration));
}).map(Instance::getId);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public <T, P extends Publisher<T>> Mono<ServerResponse> body(P publisher, Class<T> elementClass) {
Assert.notNull(publisher, "Publisher must not be null");
Assert.notNull(elementClass, "Element Class must not be null");
return new DefaultEntityResponseBuilder<>(publisher,
BodyInserters.fromPublisher(publisher, elementClass))
.headers(this.headers)
.status(this.statusCode)
.build()
.map(entityResponse -> entityResponse);
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private String formatBody(@Nullable MediaType contentType, Mono<byte[]> body) {
return body
.map(bytes -> {
if (contentType == null) {
return bytes.length + " bytes of content (unknown content-type).";
}
Charset charset = contentType.getCharset();
if (charset != null) {
return new String(bytes, charset);
}
if (PRINTABLE_MEDIA_TYPES.stream().anyMatch(contentType::isCompatibleWith)) {
return new String(bytes, StandardCharsets.UTF_8);
}
return bytes.length + " bytes of content.";
})
.defaultIfEmpty("No content")
.onErrorResume(ex -> Mono.just("Failed to obtain content: " + ex.getMessage()))
.block(this.timeout);
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Delete {@literal key}.
*
* @param key must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/del">Redis Documentation: DEL</a>
*/
default Mono<Long> del(ByteBuffer key) {
Assert.notNull(key, "Key must not be null!");
return del(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public <T, P extends Publisher<T>> Mono<ServerResponse> body(P publisher,
ParameterizedTypeReference<T> typeReference) {
Assert.notNull(publisher, "Publisher must not be null");
Assert.notNull(typeReference, "ParameterizedTypeReference must not be null");
return new DefaultEntityResponseBuilder<>(publisher,
BodyInserters.fromPublisher(publisher, typeReference))
.headers(this.headers)
.status(this.statusCode)
.build()
.map(entityResponse -> entityResponse);
}
代码示例来源:origin: codecentric/spring-boot-admin
/**
* Remove a specific instance from services
*
* @param id the instances id to unregister
* @return the id of the unregistered instance
*/
public Mono<InstanceId> deregister(InstanceId id) {
return repository.computeIfPresent(id, (key, instance) -> Mono.just(instance.deregister()))
.map(Instance::getId);
}
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Get the time to live for {@code key} in seconds.
*
* @param key must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/ttl">Redis Documentation: TTL</a>
*/
default Mono<Long> ttl(ByteBuffer key) {
Assert.notNull(key, "Key must not be null!");
return ttl(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<ServerResponse> syncBody(Object body) {
Assert.notNull(body, "Body must not be null");
Assert.isTrue(!(body instanceof Publisher),
"Please specify the element class by using body(Publisher, Class)");
return new DefaultEntityResponseBuilder<>(body,
BodyInserters.fromObject(body))
.headers(this.headers)
.status(this.statusCode)
.build()
.map(entityResponse -> entityResponse);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected Mono<String> resolveUrlPathInternal(String resourceUrlPath,
List<? extends Resource> locations, ResourceResolverChain chain) {
return chain.resolveUrlPath(resourceUrlPath, locations)
.flatMap(baseUrl -> {
if (StringUtils.hasText(baseUrl)) {
VersionStrategy strategy = getStrategyForPath(resourceUrlPath);
if (strategy == null) {
return Mono.just(baseUrl);
}
return chain.resolveResource(null, baseUrl, locations)
.flatMap(resource -> strategy.getResourceVersion(resource)
.map(version -> strategy.addVersion(baseUrl, version)));
}
return Mono.empty();
});
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Get the time to live for {@code key} in milliseconds.
*
* @param key must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/ttl">Redis Documentation: TTL</a>
*/
default Mono<Long> pTtl(ByteBuffer key) {
Assert.notNull(key, "Key must not be null!");
return pTtl(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput);
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
@Override
public <T> Mono<T> findById(String id, Class<T> entityType, @Nullable String index, @Nullable String type) {
Assert.notNull(id, "Id must not be null!");
return doFindById(id, getPersistentEntity(entityType), index, type)
.map(it -> resultMapper.mapEntity(it, entityType));
}
代码示例来源:origin: spring-projects/spring-framework
private Mono<? extends Resource> transform(String content, Resource resource,
ResourceTransformerChain chain, ServerWebExchange exchange) {
if (!content.startsWith(MANIFEST_HEADER)) {
if (logger.isTraceEnabled()) {
logger.trace(exchange.getLogPrefix() +
"Skipping " + resource + ": Manifest does not start with 'CACHE MANIFEST'");
}
return Mono.just(resource);
}
return Flux.generate(new LineInfoGenerator(content))
.concatMap(info -> processLine(info, exchange, resource, chain))
.reduce(new ByteArrayOutputStream(), (out, line) -> {
writeToByteArrayOutputStream(out, line + "\n");
return out;
})
.map(out -> {
String hash = DigestUtils.md5DigestAsHex(out.toByteArray());
writeToByteArrayOutputStream(out, "\n" + "# Hash: " + hash);
return new TransformedResource(resource, out.toByteArray());
});
}
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Get size of set at {@literal key}.
*
* @param key must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/scard">Redis Documentation: SCARD</a>
*/
default Mono<Long> sCard(ByteBuffer key) {
Assert.notNull(key, "Key must not be null!");
return sCard(Mono.just(new KeyCommand(key))).next().map(NumericResponse::getOutput);
}
代码示例来源:origin: spring-projects/spring-framework
ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {
Assert.notNull(inputStream, "'inputStream' must not be null");
Assert.notNull(bufferFactory, "'bufferFactory' must not be null");
Assert.notNull(elementType, "'elementType' must not be null");
return Mono.from(inputStream).map(value ->
encodeValue(value, mimeType, bufferFactory, elementType, hints, encoding)).flux();
ResolvableType listType =
ResolvableType.forClassWithGenerics(List.class, elementType);
return Flux.from(inputStream).collectList().map(list ->
encodeValue(list, mimeType, bufferFactory, listType, hints,
encoding)).flux();
代码示例来源:origin: spring-projects/spring-framework
return Mono.just(BeanUtils.instantiateClass(ctor));
return WebExchangeDataBinder.extractValuesToBind(exchange).map(bindValues -> {
ConstructorProperties cp = ctor.getAnnotation(ConstructorProperties.class);
String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor));
代码示例来源:origin: spring-projects/spring-data-redis
/**
* Set multiple keys to multiple values using key-value pairs provided in {@literal tuple}.
*
* @param keyValuePairs must not be {@literal null}.
* @return
* @see <a href="http://redis.io/commands/mset">Redis Documentation: MSET</a>
*/
default Mono<Boolean> mSet(Map<ByteBuffer, ByteBuffer> keyValuePairs) {
Assert.notNull(keyValuePairs, "Key-value pairs must not be null!");
return mSet(Mono.just(MSetCommand.mset(keyValuePairs))).next().map(BooleanResponse::getOutput);
}
内容来源于网络,如有侵权,请联系作者删除!