1 19 package org.netbeans.modules.j2ee.weblogic9.util; 20 21 import java.io.*; 22 import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport; 23 24 import org.openide.*; 25 import org.openide.windows.*; 26 27 34 public class WLTailer extends Thread { 35 36 40 private static final int delay = 1000; 41 42 45 private File file; 46 47 50 private InputStream inputStream; 51 52 55 private InputOutput io; 56 57 63 public WLTailer(File file, String uri) { 64 this.file = file; 66 io = UISupport.getServerIO(uri); 67 if (io == null) { 68 return; } 70 71 try { 73 io.getOut().reset(); 74 } catch (IOException ioe) { 75 } 77 io.select(); 78 start(); 79 } 80 81 87 public WLTailer(InputStream inputStream, String uri) { 88 this.inputStream = inputStream; 90 io = UISupport.getServerIO(uri); 91 if (io == null) { 92 return; } 94 95 try { 97 io.getOut().reset(); 98 } catch (IOException ioe) { 99 } 101 io.select(); 102 start(); 103 } 104 105 109 public void run() { 110 try { 111 if (file != null) { 114 inputStream = new FileInputStream(file); 115 } 116 117 InputStreamReader reader = new InputStreamReader(inputStream); 119 120 char[] chars = new char[1024]; 123 while (true) { 124 while (reader.ready()) { 126 io.getOut().println(new String (chars, 0, reader.read(chars))); 127 } 128 129 try { 131 Thread.sleep(delay); 132 } catch (InterruptedException e) { 133 } 135 } 136 } catch (FileNotFoundException e) { 137 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 138 return; 139 } catch (IOException e) { 140 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 141 } finally { 142 try { 144 inputStream.close(); 145 } catch (IOException e) { 146 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 147 } 148 } 149 } 150 151 } 152 | Popular Tags |