1 19 20 package org.netbeans.lib.cvsclient.connection; 21 22 import org.netbeans.lib.cvsclient.command.CommandAbortedException; 23 import org.netbeans.lib.cvsclient.util.LoggedDataInputStream; 24 import org.netbeans.lib.cvsclient.util.LoggedDataOutputStream; 25 26 import java.io.IOException ; 27 import java.io.BufferedInputStream ; 28 import java.io.BufferedOutputStream ; 29 30 35 public class ExtConnection extends AbstractConnection { 36 37 private final String command; 38 39 private Process process; 40 41 47 public ExtConnection(String command) { 48 this.command = command; 49 } 50 51 public void open() throws AuthenticationException, CommandAbortedException { 52 try { 53 process = Runtime.getRuntime().exec(command); 54 setInputStream(new LoggedDataInputStream(new BufferedInputStream (process.getInputStream()))); 55 setOutputStream(new LoggedDataOutputStream(new BufferedOutputStream (process.getOutputStream()))); 56 } catch (IOException e) { 57 throw new AuthenticationException(e, "Failed to execute: " + command); 58 } 59 } 60 61 public void verify() throws AuthenticationException { 62 try { 63 open(); 64 verifyProtocol(); 65 process.destroy(); 66 } catch (Exception e) { 67 throw new AuthenticationException(e, "Failed to execute: " + command); 68 } 69 } 70 71 public void close() throws IOException { 72 if (isOpen()) { 73 process.destroy(); 74 } 75 } 76 77 public boolean isOpen() { 78 if (process == null) return false; 79 try { 80 process.exitValue(); 81 return false; 82 } catch (IllegalThreadStateException e) { 83 return true; 84 } 85 } 86 87 public int getPort() { 88 return 0; 89 } 90 91 public void modifyInputStream(ConnectionModifier modifier) throws IOException { 92 modifier.modifyInputStream(getInputStream()); 93 } 94 95 public void modifyOutputStream(ConnectionModifier modifier) throws IOException { 96 modifier.modifyOutputStream(getOutputStream()); 97 } 98 } 99 | Popular Tags |