Java 为什么我会丢失控制台输出?
我在JUnit测试中有以下代码:Java 为什么我会丢失控制台输出?,java,eclipse,stream,Java,Eclipse,Stream,我在JUnit测试中有以下代码: public class CvsCommandTest { ... @Test public void test() { PServerConnection con = new PServerConnection(root); GlobalOptions globalOptions = new GlobalOptions(); globalOptions.setCVSRoot(root.toStri
public class CvsCommandTest {
...
@Test
public void test() {
PServerConnection con = new PServerConnection(root);
GlobalOptions globalOptions = new GlobalOptions();
globalOptions.setCVSRoot(root.toString());
Client client = new Client(con, new StandardAdminHandler());
client.setLocalPath(LOCAL_PATH);
client.getEventManager().addCVSListener(new BasicListener());
CheckoutCommand checkoutCmd = new CheckoutCommand();
checkoutCmd.setBuilder(null);
checkoutCmd.setModule("Outils");
try {
client.getConnection().open();
LOG.info("CVS checkout : " + checkoutCmd.getCVSCommand());
boolean successCheckout = client.executeCommand(checkoutCmd,globalOptions );
LOG.info("Checkout COMPLETED : " + successCheckout);
...
调试时的输出为:
[信息]fr.package.CvsCommandTest-CVS签出:签出
-努蒂尔斯
cvs签出:更新Outils
第一行是我的日志,第二行来自侦听器,但我没有得到剩余的日志。
basicListener的定义如下:
import java.io.PrintStream;
import org.netbeans.lib.cvsclient.event.CVSAdapter;
import org.netbeans.lib.cvsclient.event.MessageEvent;
public class BasicListener extends CVSAdapter {
/** * Stores a tagged line */
private final StringBuffer taggedLine = new StringBuffer();
/**
* Called when the server wants to send a message to be displayed to the
* user. The message is only for information purposes and clients can choose
* to ignore these messages if they wish.
*
* @param e
* the event
*/
public void messageSent(MessageEvent e) {
String line = e.getMessage();
PrintStream stream = e.isError() ? System.err : System.out;
if (e.isTagged()) {
String message = MessageEvent.parseTaggedMessage(taggedLine, line);
if (message != null) {
stream.println(message);
}
} else {
stream.println(line);
}
stream.close();
}
}
我错过了什么?把评论交上来回答 System.out-stream.close();-->晚安… 说明: 由于他在关闭
系统时使用系统.out
输出他的日志消息。out
@请参阅公共无效消息发送(MessageEvent e)
,流.close()的结尾
System.out已关闭,无法再使用,因此祝System.out晚安
解决方案是:
删除流.close()代码>命令System.out-stream.close();-->晚安