PageRenderTime 45ms CodeModel.GetById 38ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/packages/apps/get-a-robot-vpn-frontend/src/org/codeandroid/vpnc_frontend/LoggingThread.java

http://get-a-robot-vpnc.googlecode.com/
Java | 56 lines | 49 code | 7 blank | 0 comment | 5 complexity | 4a2d6268bad14afd4fc11f52c41cc5c8 MD5 | raw file
 1package org.codeandroid.vpnc_frontend;
 2
 3import java.io.BufferedReader;
 4import java.io.IOException;
 5import java.io.InputStream;
 6import java.io.InputStreamReader;
 7import java.io.PrintWriter;
 8
 9public class LoggingThread extends Thread
10{
11
12	private BufferedReader bufferedReader;
13	private PrintWriter logWriter;
14	private String prefix;
15	private boolean quit = false;
16	private int priority;
17
18	public LoggingThread(InputStream inputStream, PrintWriter logWriter, String prefix, int priority)
19	{
20		this.prefix = prefix;
21		this.logWriter = logWriter;
22		bufferedReader = new BufferedReader( new InputStreamReader( inputStream ) );
23		this.priority = priority;
24	}
25
26	@Override
27	public void run()
28	{
29		try
30		{
31			for( String line = bufferedReader.readLine(); line != null && !quit; line = bufferedReader.readLine() )
32			{
33				Util.printLog( priority, prefix + line );
34				if( logWriter != null )
35				{
36					logWriter.println( prefix + line );
37				}
38			}
39		}
40		catch( IOException e )
41		{
42			Util.error( prefix + e.getMessage(), e );
43		}
44		finally
45		{
46			logWriter.flush();
47			logWriter.close();
48		}
49	}
50
51	public void quit()
52	{
53		quit = true;
54	}
55
56}