基本上,我有一个URL,可以在发布新消息时从聊天室传输xml更新.我想将该URL转换为InputStream并继续读取它,只要保持连接并且只要我没有发送Thread.interrupt().我遇到的问题是,当从流中读取内容时,BufferedReader.ready()似乎不会成为现实.
我正在使用以下代码:
BufferedReader buf = new BufferedReader(new InputStreamReader(ins));
String str = "";
while(Thread.interrupted() != true)
{
connected = true;
debug("Listening...");
if(buf.ready())
{
debug("Something to be read.");
if ((str = buf.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
urlContents += String.format("%s%n", str);
urlContents = filter(urlContents);
}
}
// Give the system a chance to buffer or interrupt.
try{Thread.sleep(1000);} catch(Exception ee) {debug("Caught thread exception.");}
}
Run Code Online (Sandbox Code Playgroud)
当我运行代码并将某些内容发布到聊天室时,buf.ready()永远不会成为现实,从而导致行不会被读取.但是,如果我跳过"buf.ready()"部分并直接读取行,它会阻止进一步操作直到读取行.
我如何a)让buf.ready()返回true,或者b)以防止阻塞的方式执行此操作?
詹姆斯,先谢谢你
我有一个Java应用程序,其本质上就像一个即时消息类型的程序.在最近使用Unity界面"升级"到Ubuntu之前,我在系统托盘中显示了一个简单的图标.我知道有很多关于回到这个托盘的最初目的的讨论,并且不想在这里讨论.相反,我正在寻找一个简单而简洁的教程或文档,介绍如何将我的应用程序正确地集成到消息传递系统中.我想要弹出通知的新消息,我已经能够通过libnotify来做到这一点,但是我不知道如何将应用程序本身添加为消息菜单下的条目.任何帮助我指向正确方向的人都会非常感激.我需要该应用程序继续跨平台工作.