1 | public void send(String in) throws Exception {↵ | | 1 | public void send(String in) throws Exception {↵
|
2 | inputStream.write(in.getBytes());↵ | | 2 | inputStream.write(in.getBytes());↵
|
3 | inputStream.flush();↵ | | 3 | inputStream.flush();↵
|
4 | inputStream.close();↵ | | 4 | inputStream.close();↵
|
5 | }↵ | | 5 | }↵
|
|
6 | public void send(InputStream in) throws Exception {↵ | | 6 | public void send(InputStream in) throws Exception {↵
|
7 | StreamUtils.streamCopy(in, inputStream);↵ | | 7 | StreamUtils.streamCopy(in, inputStream);↵
|
8 | inputStream.flush();↵ | | 8 | inputStream.flush();↵
|
9 | inputStream.close();↵ | | 9 | inputStream.close();↵
|
10 | }↵ | | 10 | }↵
|
|
11 | public int waitFor() throws Exception {↵ | | 11 | public int waitFor() throws Exception {↵
|
12 | int exitVal = p.waitFor();↵ | | 12 | int exitVal = p.waitFor();↵
|
|
13 | return exitVal;↵ | | 13 | return exitVal;↵
|
14 | }↵ | | 14 | }↵
|
|
15 | /**↵ | | 15 | /**↵
|
16 | * ↵ | | 16 | ↵
|
17 | ↵ | | 17 | *↵
|
18 | * return error↵ | | 18 | * return error↵
|
19 | * ↵ | | 19 | *↵
|
20 | ↵ | | |
|
21 | * @return↵ | | 20 | * @return @throws↵
|
22 | * @throws Exception↵ | | 21 | * Exception↵
|
23 | */↵ | | 22 | */↵
|
24 | public String getErrorString() throws Exception {↵ | | 23 | public String getErrorString() throws Exception {↵
|
25 | String str = errorStream.getBuffer();↵ | | 24 | String str = errorStream.getBuffer();↵
|
|
26 | return str;↵ | | 25 | return str;↵
|
27 | }↵ | | 26 | }↵
|
|
28 | /**↵ | | 27 | /**↵
|
29 | * ↵ | | 28 | *↵
|
30 | ↵ | | |
|
31 | * return output↵ | | 29 | * return output↵
|
32 | * ↵ | | 30 | *↵
|
33 | ↵ | | |
|
34 | * @return↵ | | 31 | * @return↵
|
35 | * @throws↵ | | 32 | @throws↵
|
36 | Exception↵ | | 33 | * Exception↵
|
37 | */↵ | | 34 | */↵
|
38 | public String getOutputString() throws Exception {↵ | | 35 | public String getOutputString() throws Exception {↵
|
39 | String str = outputStream.getBuffer();↵ | | 36 | String str = outputStream.getBuffer();↵
|
|
40 | return str;↵ | | 37 | return str;↵
|
41 | }↵ | | 38 | }↵
|
|
42 | /*↵ | | 39 | /*↵
|
43 | * wait for stream threads to die↵ | | 40 | * wait for stream threads to die↵
|
44 | * ↵ | | 41 | ↵
|
45 | ↵ | | 42 | *↵
|
46 | */↵ | | 43 | */↵
|
47 | public void waitForThreads() throws Exception {↵ | | 44 | public void waitForThreads() throws Exception {↵
|
48 | outputStream.join();↵ | | 45 | outputStream.join();↵
|
49 | errorStream.join();↵ | | 46 | errorStream.join();↵
|
50 | }↵ | | 47 | }↵
|
|
51 | public class StreamThread extends Thread {↵ | | 48 | public class StreamThread extends Thread {↵
|
52 | InputStream is;↵ | | 49 | InputStream is;↵
|
|
53 | StringBuffer buf;↵ | | 50 | StringBuffer buf;↵
|
|
54 | public StreamThread(InputStream theInputStream) {↵ | | 51 | public StreamThread(InputStream ↵
|
55 | this.is = theInputStream;↵ | | |
|
|
56 | ↵ | | 52 | is) {↵
|
| | | 53 | this.is = is;↵
|
|
57 | buf = new StringBuffer();↵ | | 54 | buf = new StringBuffer();↵
|
58 | }↵ | | |
|
|
59 | @Override↵ | | |
|
60 | ↵ | | 55 | }↵
|
|
61 | public void run() {↵ | | 56 | public void run() {↵
|
62 | try {↵ | | 57 | try {↵
|
63 | InputStreamReader isr = new InputStreamReader(is);↵ | | 58 | InputStreamReader isr = new InputStreamReader(is);↵
|
64 | BufferedReader br = new BufferedReader(isr);↵ | | 59 | BufferedReader br = new BufferedReader(isr);↵
|
65 | String line = null;↵ | | 60 | String line = null;↵
|
|
66 | while ((line = br.readLine()) != null) {↵ | | 61 | while ((line = br.readLine()) != null) {↵
|
67 | LOG.info(">" + line); //$NON-NLS-1$↵ | | 62 | LOG.info(">" + line); //$NON-NLS-1$↵
|
68 | buf.append(line + "\n"); //$NON-NLS-1$↵ | | 63 | buf.append(line + "\n");↵
|
69 | }↵ | | |
|
70 | ↵ | | |
|
| | | 64 | }↵
|
71 | } catch (IOException ioe) {↵ | | 65 | } catch (IOException ioe) {↵
|
72 | ioe.printStackTrace();↵ | | 66 | ioe.printStackTrace();↵
|
73 | }↵ | | |
|
74 | }↵ | | |
|
|
75 | ↵ | | 67 | }↵
|
| | | 68 | }↵
|
|
76 | public String getBuffer() {↵ | | 69 | public String getBuffer() {↵
|
77 | return buf.toString() | | 70 | return buf.toString()
|