⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outputtostring.java

📁 MoMEUnit是一个单元测试的J2ME的应用程序xUnit架构实例。这是来自JUnit框架
💻 JAVA
字号:
package org.momeunit.ant.core;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;/** * Class that cumulates input read from {@link InputStream}. Provides methods * {@link #getOutputString()} for accessing cumulated input as string. Sends * input to pipe if requested. *  * @author Sergio Morozov * @version 1.1.2 */public class OutputToString extends OutputPipe{  private StringBuffer sb = null;  private boolean endOfOutput = false;  /**   * Instantiates OutputToString object with given InputStream.   *    * @param pipeIn   *          the InputStream to read from.   * @since 1.1   */  public OutputToString(InputStream pipeIn)  {    super(pipeIn);  }  /**   * Reads input from {@link InputStream} and cumulates it until input is   * closed. Sends input to pipe if requested.   *    * @see OutputPipe#run()   */  public void run()  {    BufferedReader reader = new BufferedReader(new InputStreamReader(this        .getInputStream()));    this.sb = new StringBuffer();    OutputStream out = this.getOutpuStream();    try    {      for (String line; (line = reader.readLine()) != null;)      {        sb.append(line).append('\n');        if (out != null) out.write((line + '\n').getBytes());      }    } catch (IOException e)    {} finally    {      setEndOfOutput();      try      {        if (out != null && out != System.out && out != System.err) out.close();        if (reader != null) reader.close();      } catch (IOException e)      {}    }  }  private synchronized void setEndOfOutput()  {    this.endOfOutput = true;    notifyAll();  }  /**   * Returns gathered input as {@link String}.   *    * @return the cumulated input as {@link String}.   * @since 1.1   */  public synchronized String getOutputString()  {    while (!this.endOfOutput)    {      try      {        wait();      } catch (InterruptedException e)      {}    }    return this.sb.toString();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -