1 19 20 package org.netbeans.lib.cvsclient.connection; 21 22 import java.io.IOException ; 23 24 import org.netbeans.lib.cvsclient.util.*; 25 import org.netbeans.lib.cvsclient.request.*; 26 27 28 34 public abstract class AbstractConnection implements Connection { 35 36 37 40 private String repository = null; 41 42 45 private LoggedDataInputStream inputStream; 46 47 50 private LoggedDataOutputStream outputStream; 51 52 53 public AbstractConnection() { 54 } 55 56 60 public LoggedDataInputStream getInputStream() { 61 return inputStream; 62 } 63 64 69 protected final void setInputStream(LoggedDataInputStream inputStream) { 70 if (this.inputStream == inputStream) return ; 71 if (this.inputStream != null) { 72 try { 73 this.inputStream.close(); 74 } catch (IOException ioex) {} 75 } 76 this.inputStream = inputStream; 77 } 78 79 83 public LoggedDataOutputStream getOutputStream() { 84 return outputStream; 85 } 86 87 92 protected final void setOutputStream(LoggedDataOutputStream outputStream) { 93 if (this.outputStream == outputStream) return ; 94 if (this.outputStream != null) { 95 try { 96 this.outputStream.close(); 97 } catch (IOException ioex) {} 98 } 99 this.outputStream = outputStream; 100 } 101 102 106 public String getRepository() { 107 return repository; 108 } 109 110 114 public void setRepository(String repository) { 115 this.repository = repository; 116 } 117 118 122 protected void verifyProtocol() throws IOException { 123 try { 124 outputStream.writeBytes(new RootRequest(repository).getRequestString(), "US-ASCII"); 125 outputStream.writeBytes(new UseUnchangedRequest().getRequestString(), "US-ASCII"); 126 outputStream.writeBytes(new ValidRequestsRequest().getRequestString(), "US-ASCII"); 127 outputStream.writeBytes("noop \n", "US-ASCII"); 128 } catch (UnconfiguredRequestException e) { 129 throw new RuntimeException ("Internal error verifying CVS protocol: " + e.getMessage()); 130 } 131 outputStream.flush(); 132 133 StringBuffer responseNameBuffer = new StringBuffer (); 134 int c; 135 while ((c = inputStream.read()) != -1) { 136 responseNameBuffer.append((char)c); 137 if (c == '\n') break; 138 } 139 140 String response = responseNameBuffer.toString(); 141 if (!response.startsWith("Valid-requests")) { 142 throw new IOException ("Unexpected server response: " + response); 143 } 144 } 145 } 146 | Popular Tags |