Last change
on this file since 29648 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
|
Rev | Line | |
---|
[26189] | 1 | package org.terrier.indexing;
|
---|
| 2 |
|
---|
| 3 | import java.io.BufferedOutputStream;
|
---|
| 4 | import java.io.BufferedReader;
|
---|
| 5 | import java.io.IOException;
|
---|
| 6 | import java.io.FileOutputStream;
|
---|
| 7 | import java.io.InputStream;
|
---|
| 8 | import java.io.InputStreamReader;
|
---|
| 9 | import java.io.PrintWriter;
|
---|
| 10 | import java.lang.Thread;
|
---|
| 11 |
|
---|
| 12 | class StreamGobbler
|
---|
| 13 | extends 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.