Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/util/LauncherOutputStream.java


1   /*
2    * LauncherOutputStream.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:30 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.util;
12  
13  import java.io.IOException;
14  import java.io.OutputStream;
15  import java.io.PrintStream;
16  
17  /**
18   * Redirects all standard output and standard errors to a stream.
19   *
20   * Please note that this class will only work with the app launcher
21   * because all of the output is directed to a native method in the app
22   * launcher Native (C++) code.
23   *
24   * @author Dan Schroeder
25   * @version 2.2
26   */
27  public class LauncherOutputStream
28     extends OutputStream
29  {
30     private StringBuffer buf = new StringBuffer ( 4096 );
31  
32     private native void writeToConsole ( String s );
33  
34     public LauncherOutputStream ( )
35     {
36        PrintStream ps = new PrintStream ( this, false );
37        System.setErr ( ps );
38        System.setOut ( ps );
39     }
40  
41     public synchronized void write ( int i )
42        throws IOException
43     {
44        char c = (char)i;
45  
46        if ( c == '\n' )
47        {
48           buf.append ( "\r\n" );
49           writeToConsole ( buf.toString() );
50           buf.setLength ( 0 );
51        }
52        else if ( c != '\r' )
53        {
54           buf.append ( c );
55        }
56     }
57  }