1 11 package org.eclipse.team.internal.ccvs.core.connection; 12 13 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.io.OutputStream ; 17 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; 20 import org.eclipse.team.internal.ccvs.core.IServerConnection; 21 import org.eclipse.team.internal.ccvs.core.util.Util; 22 import org.eclipse.team.internal.core.streams.PollingInputStream; 23 import org.eclipse.team.internal.core.streams.PollingOutputStream; 24 import org.eclipse.team.internal.core.streams.TimeoutInputStream; 25 import org.eclipse.team.internal.core.streams.TimeoutOutputStream; 26 27 33 public class ExtConnection implements IServerConnection { 34 35 private ICVSRepositoryLocation location; 37 private String password; 38 39 InputStream inputStream; 41 42 OutputStream outputStream; 44 45 Process process; 47 48 protected ExtConnection(ICVSRepositoryLocation location, String password) { 49 this.location = location; 50 this.password = password; 51 } 52 53 56 public void close() throws IOException { 57 try { 58 if (inputStream != null) inputStream.close(); 59 } finally { 60 inputStream = null; 61 try { 62 if (outputStream != null) outputStream.close(); 63 } finally { 64 outputStream = null; 65 if (process != null) process.destroy(); 66 } 67 } 68 } 69 70 74 public InputStream getInputStream() { 75 return inputStream; 76 } 77 78 82 public OutputStream getOutputStream() { 83 return outputStream; 84 } 85 86 91 public void open(IProgressMonitor monitor) throws IOException { 92 String [] command = ((CVSRepositoryLocation)location).getExtCommand(password); 93 boolean connected = false; 94 try { 95 process = Util.createProcess(command, monitor); 96 97 inputStream = new PollingInputStream(new TimeoutInputStream(process.getInputStream(), 98 8192 , 1000 , -1 ), location.getTimeout(), monitor); 99 outputStream = new PollingOutputStream(new TimeoutOutputStream(process.getOutputStream(), 100 8192 , 1000 , 1000 ), location.getTimeout(), monitor); 101 102 connected = true; 104 } finally { 105 if (! connected) { 106 try { 107 close(); 108 } finally { 109 } 111 } 112 } 113 } 114 } 115 | Popular Tags |