KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > backend > ProcessWatcher


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.backend;
25
26 import java.util.logging.Level JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.io.IOException JavaDoc;
29
30
31 /**
32  * Workaround for now for the lack of APIs to access wsgen and wsimport utilities
33  * @author Jerome Dochez
34  */

35 public class ProcessWatcher {
36     
37     Process JavaDoc toWatch = null;
38     
39     /** Creates a new instance of ProcessWatcher */
40     public ProcessWatcher(Process JavaDoc p) {
41         toWatch = p;
42     }
43     
44     public int watch() {
45         InputStream JavaDoc input = toWatch.getInputStream();
46         InputStream JavaDoc error = toWatch.getErrorStream();
47         boolean notDone = true;
48         do {
49             try {
50                 while (input.available()>0) {
51                     dump(input);
52                 }
53                 while (error.available()>0) {
54                     dump(error);
55                 }
56             } catch(IOException JavaDoc e) {
57                 
58             }
59             try {
60                 toWatch.exitValue();
61                 notDone = false;
62             } catch(IllegalThreadStateException JavaDoc e) {
63             }
64         } while (notDone);
65         return toWatch.exitValue();
66     }
67     
68     public void dump(InputStream JavaDoc is) throws IOException JavaDoc {
69         if (is.available()>0) {
70             byte[] bytes = new byte[is.available()];
71             is.read(bytes, 0, bytes.length);
72             System.out.println(new String JavaDoc(bytes));
73         }
74     }
75 }
76
Popular Tags