草庐IT

stream_socket_client

全部标签

Java 8 Streams - 对元组流进行分组

编辑::我正在改写问题以便更清楚这段代码是我写的List>list=newArrayList>();list.add(newImmutablePair(1,1));list.add(newImmutablePair(1,1));list.add(newImmutablePair(1,1));list.add(newImmutablePair(2,2));list.add(newImmutablePair(2,2));list.add(newImmutablePair(2,2));list.add(newImmutablePair(3,3));list.add(newImmutableP

java.util.stream.Collectors : Why is the summingInt implemented with an array?

标准收集器summingInt在内部创建一个长度为1的数组:publicstaticCollectorsummingInt(ToIntFunctionmapper){returnnewCollectorImpl(()->newint[1],(a,t)->{a[0]+=mapper.applyAsInt(t);},(a,b)->{a[0]+=b[0];returna;},a->a[0],CH_NOID);}我想知道是否可以只定义:privateCollectorsummingInt(ToIntFunctionmapper){returnCollector.of(()->0,(a,t)->

java - FlyingSaucer renderer.setDocument 抛出 "Stream closed"异常

我在使用找到的简单示例创建PDF时遇到问题here.这是我第一次尝试使用它,我尝试了一些东西并进行了大量搜索,但没有找到产生错误的原因。错误源自renderer.setDocument(url);行。如果有人有任何想法、建议或替代方案,我们将不胜感激。packageflyingsaucerpdf;importjava.io.*;importcom.lowagie.text.DocumentException;importorg.xhtmlrenderer.pdf.ITextRenderer;publicclassFirstDoc{publicstaticvoidmain(String[

java - 将 spring-cloud 与 netflix Eureka 一起使用时,如何让 Discovery Client 工作?

我正在尝试使用SpringCloud和Netflix插件(如Hystrix、Eureka和Ribbon)制作一个基本项目,以了解其工作原理。我正在尝试制作的项目是一个简单的消息服务器,它将保留消息。还有一个消息客户端,它只会向服务器询问消息,我想为此使用自动发现客户端,或RestTemplate发现。但我不能去工作。我有以下结构:消息客户端(Eureka客户端)消息服务器(Eureka客户端)配置服务(配置服务器)发现服务(Eureka服务器)我目前做的是启动配置服务,并在它们通过以下结构连接时将application.yml详细信息公开给所有这些“应用程序/客户端”:config-s

java - 如何使用java Stream检查集合是否为空

我是Java8的新手。我无法理解以下代码中的错误。思路是发Collection如果它不是空的。但是如果集合是空的而不是发送HttpStatus.NOT_FOUND实体响应。@RequestMapping(value="/find/pks",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)publicResponseEntity>getUsers(@RequestBodyfinalCollectionpks){returnStreamSupport.stream(userRepository.findA

java - 从 'stream()' 或 'parallelStream()' 中捕获异常会丢失正确的值

在下面的代码中,当从for迭代中捕获NumberFormatException时,适当形式的字符串出现在strList中第一个坏字符串之前(即"illegal_3")已成功解析(即"1"和"2"已解析为整数1和2)。publicvoidtestCaughtRuntimeExceptionOutOfIteration(){ListstrList=Stream.of("1","2","illegal_3","4","illegal_5","6").collect(Collectors.toList());ListintList=newArrayList();try{for(Stringst

java - Linq C# 中 Java 的 Stream#Peek 方法的等价物是什么?

我已经习惯使用Java的Stream#Peek方法,因为它是调试中间流操作的有用方法。对于那些不熟悉Stream#Peek的人方法,下面显示了它的定义:Streampeek(Consumeraction)Returnsastreamconsistingoftheelementsofthisstream,additionallyperformingtheprovidedactiononeachelementaselementsareconsumedfromtheresultingstream.Thisisanintermediateoperation.考虑下面这个简单的例子:Listin

java - Stream reduce() 要求到底包含什么?

在并行流上使用reduce()操作时,theOCPexambook说明reduce()参数必须遵守某些原则。这些原则如下:Theidentitymustbedefinedsuchthatforallelementsinthestreamu,combiner.apply(identity,u)isequaltou.Theaccumulatoroperatoropmustbeassociativeandstatelesssuchthat(aopb)opcisequaltoaop(bopc).Thecombineroperatormustalsobeassociativeandstatele

java - Web Socket 与 JMS 或 Activemq

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭8年前。Improvethisquestion我想知道JavaWeb套接字和JMS(或ActiveMq)之间有什么区别?请让我知道或有任何来源对WebSocket和JMS进行任何比较,以及在哪里使用websocket而不是以及在哪里使用Activemq而不是websocket。Activemq是JMS的一种实现。Activemq可能使用Web套接字。如果使用web套接字而不是Activemq来传输消息(具有任何类型的数据)怎么办?这可能取决于应用程序

java - Google 存储客户端库 (appengine-gcs-client) 具有不可用的依赖项 (google-http-client-parent :pom:1. 24.1)

我将appengine-gcs-client添加到我的GoogleAppEngine标准项目中:*com.google.appengine.toolsappengine-gcs-client0.7*(按照此页面上的说明操作:https://cloud.google.com/appengine/docs/standard/java/googlecloudstorageclient/setting-up-cloud-storage)编译工程报如下错误(前几天没问题):[错误]无法在项目myproject2上执行目标:无法解析项目com.myproject2:myproject2:war:1