1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.nuiton.jrst;
24
25 import java.io.BufferedReader;
26 import java.io.IOException;
27 import java.io.InputStreamReader;
28
29 import org.apache.commons.io.IOUtils;
30
31
32
33
34 public class ThreadRedirection extends Thread {
35
36 public static final String LINE_SEPARATOR = "\n";
37 protected StringBuffer str;
38 protected Process process;
39
40 public ThreadRedirection(Process p) {
41 process = p;
42 str = new StringBuffer();
43 }
44
45 @Override
46 public void run() {
47 BufferedReader reader =null;
48 try {
49
50 reader = new BufferedReader(new InputStreamReader(
51 process.getInputStream()),8193);
52
53 String line;
54 while ((line = reader.readLine()) != null) {
55
56
57
58
59
60 if(!line.startsWith("<!DOCTYPE html "))
61 {
62 str.append(line + LINE_SEPARATOR);
63 }
64 else {
65 str.append("<!DOCTYPE xsl:stylesheet [<!ENTITY nbsp ' '>]> " + LINE_SEPARATOR);
66 }
67 }
68
69
70 }
71 catch (IOException ioe) {
72 ioe.printStackTrace();
73 }
74 finally {
75 IOUtils.closeQuietly(reader);}
76 }
77
78 public String getOutput() {
79 return str.toString();
80 }
81 }