1 22 package org.netbeans.lib.cvsclient.connection; 23 24 import java.io.*; 25 26 import org.netbeans.lib.cvsclient.util.*; 27 29 40 public class LocalConnection extends AbstractConnection { 41 42 private static final String CVS_EXE_COMMAND = System.getenv("CVS_EXE") != null? 43 System.getenv("CVS_EXE") + " server": "cvs server"; 45 48 protected Process process; 49 50 53 public LocalConnection() { 54 reset(); 55 } 56 57 62 private void openConnection() 63 throws AuthenticationException { 64 try { 65 process = Runtime.getRuntime().exec(CVS_EXE_COMMAND); 66 setOutputStream(new LoggedDataOutputStream(process. 67 getOutputStream())); 68 setInputStream(new LoggedDataInputStream(process.getInputStream())); 69 } 70 catch (IOException t) { 71 reset(); 72 String locMessage = AuthenticationException.getBundleString( 73 "AuthenticationException.ServerConnection"); throw new AuthenticationException("Connection error", t, locMessage); } 76 } 77 78 private void reset() { 79 process = null; 80 setInputStream(null); 81 setOutputStream(null); 82 } 83 84 93 public void verify() throws AuthenticationException { 94 try { 95 openConnection(); 96 verifyProtocol(); 97 process.destroy(); 98 } 99 catch (Exception e) { 100 String locMessage = AuthenticationException.getBundleString( 101 "AuthenticationException.ServerVerification"); throw new AuthenticationException("Verification error", e, locMessage); } 104 finally { 105 reset(); 106 } 107 } 108 109 118 public void open() throws AuthenticationException { 119 openConnection(); 120 } 121 122 125 public boolean isOpen() { 126 return process != null; 127 } 128 129 132 public void close() throws IOException { 133 try { 134 if (process != null) { 135 process.destroy(); 136 } 137 } 138 finally { 139 reset(); 140 } 141 } 142 143 146 public int getPort() { 147 return 0; } 149 150 155 public void modifyInputStream(ConnectionModifier modifier) 156 throws IOException { 157 modifier.modifyInputStream(getInputStream()); 158 } 159 160 165 public void modifyOutputStream(ConnectionModifier modifier) 166 throws IOException { 167 modifier.modifyOutputStream(getOutputStream()); 168 } 169 170 } 171 | Popular Tags |