为什么我会丢失控制台输出?

时间:2015-11-16 16:32:52

标签: java eclipse stream

我在JUnit测试中有这个代码:

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);
...

调试时的输出是:

  

[INFO] fr.package.CvsCommandTest - CVS结帐:结帐   -N Outils

     

cvs checkout:更新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();
    }
}

我错过了什么?

1 个答案:

答案 0 :(得分:3)

转而评论回答

System.out stream.close(); - >晚安......

说明:

因为当他关闭System.out @see System.out的结尾时,public void messageSent(MessageEvent e)正在使用stream.close();输出他的日志消息,System.out System.out关闭,不能再使用了,所以晚安到stream.close();

解决方案是:

删除<div class="PamphletWidget clearfix colelem" id="pamphletu1152"> <!-- none box --> <div class="ThumbGroup clearfix grpelem" id="u1159"> <!-- none box --> <div class="popup_anchor"> <div class="Thumb popup_element clearfix" id="u1160"> <!-- group --> <div class="clearfix grpelem" id="u1235-6"> <!-- content --> <p id="u1235-2">Richard Bizley</p> <p id="u1235-4">Head of Professional Practice</p> </div> </div> </div> </div> <div class="popup_anchor" id="u1153popup"> <div class="ContainerGroup clearfix" id="u1153"> <!-- stack box --> <div class="Container clearfix grpelem" id="u1155"> <div class="clearfix grpelem" id="u1701-25"> <!-- content --> <p id="u1701-2">Richard Bizley</p> <p id="u1701-4">Head of Professional Practice</p> <p id="u1701-6">+44 (0)1223 224039</p> <p class="LifeSci-Ppl" id="u1701-9"><a class="nonblock" href="mailto:richard.bizley@avidity-ip.com">richard.bizley@avidity-ip.com</a> </p> <p id="u1701-10">&nbsp;</p> <p id="u1701-12">Fellow of the Chartered Institute of Patent Attorneys (UK) (1975); European Patent Attorney (1978); UK Registered Trade Mark Agent (1990); European Trade Mark Attorney (1996); Patent Agent Litigator (Litigation Certificate) (2002); BA (Hons) and MA in Biochemistry (Oxford).</p> <p id="u1701-14">As a biochemist of very considerable experience in the patent profession, Richard’s career has encompassed all of the major biotech patenting developments since the European Patent Office opened in 1978. In the late 1970s, Richard provided the European representation for Cetus Corporation covering matters ranging from protein isolation, through initial recombinant technology applications, to the first PCR cases. Richard advised the MRC in relation to the early genomics cases, and filed the MRC’s initial genomics case as well as spin-off technology from the human genome project.</p> <p id="u1701-16">Richard has provided representation in a list of very high profile cases at the European Patent Office at all levels, including PCR, the Harvard oncomouse case, the recombinant relaxin case, patentability of genomics (including obtaining patent grant on appeal for a ZymoGenetics case which has been regarded as seminal in biotech patentability, having been relied upon in judgements of the English Court of Appeal and Supreme Court), Schering AG’s successful attack against Biogen’s IFN Beta case, Protein Design Labs and humanised antibodies, and many many more.</p> <p id="u1701-18">Richard is recognised as one of the leading practitioners in Europe in relation to oppositions and related contentious proceedings, having very considerable experience in running opposition teams and related litigation. His experience of and familiarity with the Boards of Appeal at the EPO is of immense value to clients and, as the Director responsible for contentious proceedings, Richard inevitably deals with clients at all levels and in all commercial circumstances.</p> <p id="u1701-20">Richard has handled a number of standard and “non-conventional” cases spanning, antibodies, vaccines and small molecule drugs. This unique experience resulted in Richard’s filing of SPC applications for each of the only two antibody drug conjugates (ADCs) presently approved in Europe.</p> <p id="u1701-22">Richard is continuously recognised in peer review assessments of leading practitioners.</p> <p id="u1701-23">&nbsp;</p> </div> </div> </div> 命令