01: package com.memoire.vainstall;
02:
03: import java.io.IOException;
04: import java.io.InputStream;
05:
06: /**
07: * Feed an input stream to the details method of a VAInstallStep object
08: * as well as to VAGlobals.printDebug. Instantiate and then use start method.
09: *
10: */
11:
12: class InputStreamToDetails extends Thread {
13:
14: char[] buff = new char[128];
15: InputStream input;
16: VAInstallStep step;
17:
18: /** PrintWriter may be null. */
19: public InputStreamToDetails(InputStream input, VAInstallStep step)
20: throws IOException {
21: super ();
22: this .input = input;
23: this .step = step;
24: }
25:
26: public void run() {
27: try {
28: int buffidx = 0;
29: int aint = input.read();
30: while (aint != -1) {
31: char achar = (char) aint;
32: buff[buffidx] = achar;
33: buffidx++;
34: if (buffidx >= buff.length || achar == '\n') {
35: if (achar == '\n')
36: buffidx--;
37: String txt = new String(buff, 0, buffidx);
38: step.details(txt);
39: VAGlobals.printDebug(txt);
40: buffidx = 0;
41: }
42: aint = input.read();
43: yield();
44: }
45: if (buffidx > 0) {
46: String txt = new String(buff, 0, buffidx);
47: step.details(txt);
48: }
49: input.close();
50: } catch (IOException ioe) {
51: step.details(ioe.getMessage());
52: }
53: }
54:
55: }
|