如何在客户端和服务器之间建立多个IO流?

我正在用Java创建一个客户端/服务器对,目前只支持通过PrintWriters和BufferedReaders进行隔行扫描的文本通信,这些通信包裹在服务器和客户端的IO流中。 我想实现一个函数,它使用Image [Input / Output] Stream以一定的间隔从服务器向客户端发送BufferedImage。 问题是我希望在单独的线程中发送/接收BufferedImages,以便客户端/服务器仍然可以发送/接收文本命令。 我可以创建多个流或套接字吗? 如果是这样,那是最好的方法吗?

从java.util.function.Function获取方法名称

是否可以获取java.util.function.Function的方法名称。 我想每次都记录正在使用的方法的名称。 下面的示例打印Lambda对象,但我还没有找到一种简单的方法来获取方法名称: public class Example { public static void main(String[] args) { Example ex = new Example(); ex.callService(Integer::getInteger, “123”); } private Integer callService(Function sampleMethod, String input) { Integer output = sampleMethod.apply(input); System.out.println(“Calling method “+ sampleMethod); return output; } }

一起运行Pocketsphinx和Google TTS

我想开始一个新的活动,从一开始就识别语音,并且可以在活动开始后立即读取传入的消息。 此代码是从默认值合并的代码。 它在默认情况下运行良好。 但我想删除按钮作为触发器,而是使用语音来触发SMSReaderMain.java进一步操作。 因此,我使用pocketphinx for Android来实现它。 pocketSphinxAndroidDemo-preAlpha项目 Android文本到Speech Tutorial项目 它没有给我任何错误,但是当它在实际设备上运行时,它强制关闭。 Log cat显示这些错误 03-16 23:09:15.330: E/cmusphinx(8505): ERROR: “kws_search.c”, line 158: The word ‘/1e-60/’ is missing in the dictionary 03-16 23:09:15.330: E/cmusphinx(8505): ERROR: “kws_search.c”, line 158: The word ‘/1e-60/’ is missing in the dictionary 03-16 23:09:15.330: I/cmusphinx(8505): INFO: kws_search.c(417): KWS(beam: -1080, plp: -23, default threshold -450) […]

更通用的回报

看一些代码清理,我想知道处理这个问题的最佳方法: 有一个类有一些私有变量,如: myBool1, myBool2, myBool3 myInt1, myInt2, myInt3 myString1, myString2, myString3 执行返回值通用的getter函数的最佳方法是什么? 所以,如果我用以下内容调用getter: myNewBool=.get(“myBool1”) myNewString=.get(“myString2”) myNewInt=.get(“myInt3”) 有人有什么建议吗?

在tomcat启动时,通常只允许使用每个套接字地址(协议/网络地址/端口)?

这是server.xml中的连接器元素。 我也尝试使用8443而不是8484但是同样的错误。 SEVERE: Error starting endpoint java.lang.Exception: Socket bind failed: [730048] Only one usage of each socket address (protocol/network address/port) is normally permitted. at org.apache.tomcat.util.net.AprEndpoint.init(AprEndpoint.java:649) at org.apache.tomcat.util.net.AprEndpoint.start(AprEndpoint.java:766) at org.apache.coyote.http11.Http11AprProtocol.start(Http11AprProtocol.java:137) at org.apache.catalina.connector.Connector.start(Connector.java:1122) at org.apache.catalina.core.StandardService.start(StandardService.java:540) at org.apache.catalina.core.StandardServer.start(StandardServer.java:754) at org.apache.catalina.startup.Catalina.start(Catalina.java:595) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) Jan 23, 2014 10:05:26 AM […]

使用BufferedReader了解文件的偏移量?

我是java的新手。 我正在使用BufferedReader读取一个大文件。 我怎么知道一行的偏移量,以便我可以将它存储在其他文件中以便进行索引? 编辑:这是我的代码 path=FileSystems.getDefault().getPath(“.”,filename); br=Files.newBufferedReader(path_doc_title_index_path, Charset.defaultCharset()); int offset=0; //offset of first line. String strline=br.readline(); offset+=strline.length()+1; //offset of second line

Java ini4j – 从.ini文件中读取多个选项

我正在尝试使用ini4j读取多个值 ,文档说应该可以使用Options类。 这是我的示例.ini文件 (./dwarfs.ini) [dopey] age = 23 fortuneNumber = 11 fortuneNumber = 33 fortuneNumber = 55 这是阅读它的代码 : Ini ini = new Ini(); Config conf = new Config(); conf.setMultiOption(true); ini.setConfig(conf); ini.load(new FileReader(“./dwarfs.ini”)); 但是fortuneNumber属性在阅读后只有55,我希望它是一个数组或列表,任何东西。

如何在添加新行后进行JTable刷新

在我向JTable添加新行之后。 写入的信息转到txt文件,但我的JTable没有显示最后一个原始文件。 但是,如果我关闭程序并再次运行它,那么表中的信息就会出现。 那么,有没有办法刷新JTable的数据而不关闭应用程序并再次运行它? String[] columns = {“nume”, “compozitie”, “indicatii”, “contraindicatii”, “administrare”, “pret”, “compensabil”, “stoc”}; Object[][] data = null; try { File file = new File(“medicamente.txt”); FileReader fileReader = new FileReader(file); BufferedReader bufferedReader = new BufferedReader(fileReader); data = new Object[100][]; String line; int numLines = 0; while ((line = bufferedReader.readLine()) != null) { data[numLines] = […]

Java OpenCV训练SVM错误 – 输入样本必须是1维向量

我想检测给定图像上的微笑,但是我得到一个错误的参数错误: OpenCV Error: Incorrect size of input array (Input sample must be 1-dimensional vector) in cvPreparePredictData, file ..\..\..\..\opencv\modules\ml\src\inner_functions.cpp, line 1107 Exception in thread “main” CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\ml\src\inner_functions.cpp:1107: error: (-201) Input sample must be 1-dimensional vector in function cvPreparePredictData ] 在detectSmile(Mat face)方法的最后一行。 整个代码: public class SmileDetector { private CascadeClassifier faceDetector; private Mat image; private Mat […]

需要检查用户ID存在与struts 2

我正在使用struts 2框架并试图查看在数据库中检查用户ID存在的最佳方法。 在我的上一个项目中,我用jquery ajax做了这个,但对它不满意。 在这个项目中,我使用validation框架对客户端的输入字段和jquery validate插件进行服务器端检查。 我有一个DAO类,它调用DB来检查是否存在,我不想使用jquery ajax但是更喜欢使用struts 2validation框架。 他们是否可以使用我的DAO类输出并使用字段表达式或使用validate方法将其与我的validationxml结合使用? 如果我使用validation方法? 与执行动作类相比,此方法的执行顺序是什么? 我想要这种格式的订单,首先我做客户端validation,然后是服务器端validation,然后只有服务器端完成,我需要启动检查用户ID是否存在然后最后插入数据库? 我的字段操作validation文件如下所示, Email is required Please enter valid email id 现在我需要检查db中是否存在电子邮件,因此我有DAO类返回true或false,如何从dao类添加validation?