source: gs2-extensions/video-and-audio/trunk/src/opt/Terrier/StreamGobbler.java@ 26192

Last change on this file since 26192 was 26189, checked in by jmt12, 12 years ago

Moving the StreamGobbler - used in both plugins to prevent a full STDERR buffer killing the import - into it's own class... my computer doesn't have an issue with exactly the same class occuring twice, but Medusa's one seems stricter in this regard

File size: 1.3 KB
Line 
1package org.terrier.indexing;
2
3import java.io.BufferedOutputStream;
4import java.io.BufferedReader;
5import java.io.IOException;
6import java.io.FileOutputStream;
7import java.io.InputStream;
8import java.io.InputStreamReader;
9import java.io.PrintWriter;
10import java.lang.Thread;
11
12class StreamGobbler
13extends Thread
14{
15 InputStream is;
16 String file_path;
17 boolean output_to_file;
18
19 StreamGobbler(InputStream is)
20 {
21 this.is = is;
22 this.output_to_file = false;
23 }
24
25 StreamGobbler(InputStream is, String file_path)
26 {
27 this.is = is;
28 this.file_path = file_path;
29 this.output_to_file = true;
30 }
31
32 public void run()
33 {
34 try
35 {
36 InputStreamReader isr = new InputStreamReader(is);
37 BufferedReader br = new BufferedReader(isr);
38 String line = null;
39 if (output_to_file)
40 {
41 PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(file_path)));
42 while ( (line = br.readLine()) != null)
43 {
44 pw.println(line);
45 }
46 pw.flush();
47 pw.close();
48 }
49 else
50 {
51 while ( (line = br.readLine()) != null)
52 {
53 // Do nothing - equivalent to > /dev/null
54 }
55 }
56 }
57 catch (IOException ioe)
58 {
59 ioe.printStackTrace();
60 }
61 }
62}
Note: See TracBrowser for help on using the repository browser.