📄 outputlogger.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;import org.apache.tools.ant.Project;import org.apache.tools.ant.Task;/** * Class that reads input from {@link InputStream} and logs it to ant logging * system. Sends input to pipe if requested. * * @author Sergio Morozov * @version 1.1.2 */public class OutputLogger extends OutputPipe{ /** * Owning task. */ private Task task = null; /** * Prtority of meaasges being logged. */ private int msgPriority = Project.MSG_INFO; /** * Instantiates OutputLogger with owning task and message priority. * * @param pipeIn * InputStream of logger. * @param task * owning task. * @param msgPriority * message priority. * @since 1.1 */ public OutputLogger(InputStream pipeIn, Task task, int msgPriority) { super(pipeIn); setTask(task); setMessagePriority(msgPriority); } /** * Instantiates OutputLogger with owning task and message priority of * <code>INFO</code>. * * @param pipeIn * InputStream of logger. * @param task * owning task. * @since 1.1 */ public OutputLogger(InputStream pipeIn, Task task) { this(pipeIn, task, Project.MSG_INFO); } /** * Instantiates OutputLogger with message priority of <code>INFO</code>. * * @param pipeIn * InputStream of logger. * @since 1.1 */ public OutputLogger(InputStream pipeIn) { this(pipeIn, null); } /** * Returns message priority. * * @return the message priority. * @since 1.1 */ public int getMessagePriority() { return this.msgPriority; } /** * Sets message priority. * * @param msgPriority * the message priority to set. * @since 1.1 */ public void setMessagePriority(int msgPriority) { this.msgPriority = msgPriority; } /** * Returns owning task. * * @param task * the owning task to set. * @since 1.1 */ public void setTask(Task task) { this.task = task; } /** * Reads input from {@link InputStream} and logs it to ant logging system * until input is closed. Sends input to pipe if requested. * * @see OutputPipe#run() */ public void run() { BufferedReader reader = new BufferedReader(new InputStreamReader(this .getInputStream())); OutputStream out = this.getOutpuStream(); try { for (String line; (line = reader.readLine()) != null;) { Utility.log(this.task, line, this.msgPriority); if (out != null) out.write((line + '\n').getBytes()); } } catch (IOException e) { Utility.log(this.task, e.toString(), Project.MSG_ERR); } finally { try { if (out != null && out != System.out && out != System.err) out.close(); if (reader != null) reader.close(); } catch (IOException e) { Utility.log(this.task, e.toString(), Project.MSG_ERR); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -