summaryrefslogtreecommitdiffstats
path: root/khtml/java/org/kde/kjas/server/KJASConsoleStream.java
blob: 2c1152ed4770826f4f884465ae30c90eb3d37b4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package org.kde.kjas.server;
import java.io.*;

class KJASConsoleStream
    extends OutputStream
{
    private Console console;
    private FileOutputStream dbg_log;

    public KJASConsoleStream(Console console)
    {
        this.console = console;

        try
        {
            if( Main.log )
            {
                dbg_log = new FileOutputStream( "/tmp/kjas.log");
            }
        }
        catch( FileNotFoundException e ) {}
    }

    public void close() {}
    public void flush() {}
    public void write(byte[] b) {}
    public void write(int a) {}

    // Should be enough for the console
    public void write( byte[] bytes, int offset, int length )
    {
        try  // Just in case
        {
            String msg = new String( bytes, offset, length );
            console.append(msg);
                if( Main.log && dbg_log != null )
                {
                    dbg_log.write( msg.getBytes() );
                    dbg_log.flush();
                }
        }
        catch(Throwable t) {}
    }
}