本文整理了Java中akka.stream.javadsl.Source.from()
方法的一些代码示例,展示了Source.from()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Source.from()
方法的具体详情如下:
包路径:akka.stream.javadsl.Source
类名称:Source
方法名:from
暂无
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Set a Multipart Form url encoded body to this request saving it as a raw body.
*
* @param data the multipart-form parameters
* @param temporaryFileCreator the temporary file creator.
* @param mat a Akka Streams Materializer
* @return the modified builder
*/
public RequestBuilder bodyRaw(List<MultipartFormData.Part<Source<ByteString, ?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat) {
String boundary = MultipartFormatter.randomBoundary();
try {
ByteString materializedData = MultipartFormatter
.transform(Source.from(data), boundary)
.runWith(Sink.reduce(ByteString::concat), mat)
.toCompletableFuture()
.get();
play.api.mvc.RawBuffer buffer = new play.api.mvc.RawBuffer(materializedData.size(), temporaryFileCreator.asScala(), materializedData);
return body(new RequestBody(JavaParsers.toJavaRaw(buffer)), MultipartFormatter.boundaryToContentType(boundary));
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Failure while materializing Multipart/Form Data", e);
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Set a Multipart Form url encoded body to this request saving it as a raw body.
*
* @param data the multipart-form parameters
* @param temporaryFileCreator the temporary file creator.
* @param mat a Akka Streams Materializer
* @return the modified builder
*/
public RequestBuilder bodyRaw(List<MultipartFormData.Part<Source<ByteString, ?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat) {
String boundary = MultipartFormatter.randomBoundary();
try {
ByteString materializedData = MultipartFormatter
.transform(Source.from(data), boundary)
.runWith(Sink.reduce(ByteString::concat), mat)
.toCompletableFuture()
.get();
play.api.mvc.RawBuffer buffer = new play.api.mvc.RawBuffer(materializedData.size(), temporaryFileCreator.asScala(), materializedData);
return body(new RequestBody(JavaParsers.toJavaRaw(buffer)), MultipartFormatter.boundaryToContentType(boundary));
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Failure while materializing Multipart/Form Data", e);
}
}
代码示例来源:origin: com.typesafe.play/play
/**
* Set a Multipart Form url encoded body to this request saving it as a raw body.
*
* @param data the multipart-form parameters
* @param temporaryFileCreator the temporary file creator.
* @param mat a Akka Streams Materializer
* @return the modified builder
*/
public RequestBuilder bodyRaw(List<MultipartFormData.Part<Source<ByteString, ?>>> data, Files.TemporaryFileCreator temporaryFileCreator, Materializer mat) {
String boundary = MultipartFormatter.randomBoundary();
try {
ByteString materializedData = MultipartFormatter
.transform(Source.from(data), boundary)
.runWith(Sink.reduce(ByteString::concat), mat)
.toCompletableFuture()
.get();
play.api.mvc.RawBuffer buffer = new play.api.mvc.RawBuffer(materializedData.size(), temporaryFileCreator.asScala(), materializedData);
return body(new RequestBody(JavaParsers.toJavaRaw(buffer)), MultipartFormatter.boundaryToContentType(boundary));
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Failure while materializing Multipart/Form Data", e);
}
}
代码示例来源:origin: eclipse/ditto
/**
* Purge namespaces from some persistent storage.
*
* @param namespaceDescriptors storage-specific identifiers to describe namespaces.
* @return source of any errors during the purge.
*/
default Source<List<Throwable>, NotUsed> purgeAll(final Collection<S> namespaceDescriptors) {
return Source.from(namespaceDescriptors)
.flatMapConcat(this::purge)
.grouped(namespaceDescriptors.size())
.map(errors -> errors.stream()
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList()));
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-persistence
private Source<Success, NotUsed> dropIndices(final String collectionName, final List<String> indices) {
if (indices.isEmpty()) {
return Source.empty();
}
return Source.from(indices)
.flatMapConcat(index -> dropIndex(collectionName, index));
}
代码示例来源:origin: eclipse/ditto
private Source<Success, NotUsed> createIndices(final String collectionName, final List<Index> indices) {
if (indices.isEmpty()) {
return Source.empty();
}
return Source.from(indices)
.flatMapConcat(index -> createIndex(collectionName, index));
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-utils-persistence
private Source<Success, NotUsed> createIndices(final String collectionName, final List<Index> indices) {
if (indices.isEmpty()) {
return Source.empty();
}
return Source.from(indices)
.flatMapConcat(index -> createIndex(collectionName, index));
}
代码示例来源:origin: eclipse/ditto
private Source<Success, NotUsed> dropIndices(final String collectionName, final List<String> indices) {
if (indices.isEmpty()) {
return Source.empty();
}
return Source.from(indices)
.flatMapConcat(index -> dropIndex(collectionName, index));
}
代码示例来源:origin: eclipse/ditto
private void retrieveThingsAndSendResult(final List<String> thingIds,
@Nullable final JsonFieldSelector selectedFields,
final Command<?> command, final ActorRef resultReceiver) {
final DittoHeaders dittoHeaders = command.getDittoHeaders();
final CompletionStage<?> commandResponseSource = Source.from(thingIds)
.filter(Objects::nonNull)
.filterNot(String::isEmpty)
.filter(thingId -> THING_ID_PATTERN.matcher(thingId).matches())
.map(thingId -> {
final Command<?> toBeWrapped;
if (command instanceof RetrieveThings) {
toBeWrapped = Optional.ofNullable(selectedFields)
.map(sf -> RetrieveThing.getBuilder(thingId, dittoHeaders)
.withSelectedFields(sf)
.build())
.orElse(RetrieveThing.of(thingId, dittoHeaders));
} else {
toBeWrapped = Optional.ofNullable(selectedFields)
.map(sf -> SudoRetrieveThing.of(thingId, sf, dittoHeaders))
.orElse(SudoRetrieveThing.of(thingId, dittoHeaders));
}
return ConciergeWrapper.wrapForEnforcer(toBeWrapped);
})
.ask(calculateParallelism(thingIds), targetActor, Jsonifiable.class,
Timeout.apply(retrieveSingleThingTimeout.toMillis(), TimeUnit.MILLISECONDS))
.log("command-response", log)
.runWith(StreamRefs.sourceRef(), actorMaterializer);
PatternsCS.pipe(commandResponseSource, aggregatorDispatcher)
.to(resultReceiver);
}
内容来源于网络,如有侵权,请联系作者删除!