⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cvsssh2serverconnection.java

📁 This archive file is for Eclipse 2.1.* and Eclipse 3.0 M5(or previous) users
💻 JAVA
字号:
/* -*-mode:java; c-basic-offset:2; -*- *//******************************************************************************* * Copyright (c) 2003, Atsuhiko Yamanaka, JCraft,Inc. and others. All rights * reserved. This program and the accompanying materials are made available * under the terms of the Common Public License v1.0 which accompanies this * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html *  * Contributors: Atsuhiko Yamanaka, JCraft,Inc. - initial API and * implementation. ******************************************************************************/package org.eclipse.team.ccvs.ssh2;import java.io.*;import org.eclipse.core.runtime.IProgressMonitor;import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;import org.eclipse.team.internal.ccvs.core.IServerConnection;import org.eclipse.team.internal.ccvs.core.connection.CVSAuthenticationException;import com.jcraft.jsch.*;import org.eclipse.team.ccvs.ssh2.Policy;public class CVSSSH2ServerConnection implements IServerConnection {	private static final String COMMAND = "cvs server"; //$NON-NLS-1$	private ICVSRepositoryLocation location;	private String password;	private InputStream inputStream;	private OutputStream outputStream;	private Session session;	private Channel channel;	protected CVSSSH2ServerConnection(ICVSRepositoryLocation location, String password) {		this.location = location;		this.password = password;	}	public void close() throws IOException {		if (channel != null)			channel.disconnect();	}	public InputStream getInputStream() {		return inputStream;	}	public OutputStream getOutputStream() {		return outputStream;	}	public void open(IProgressMonitor monitor) throws IOException, CVSAuthenticationException {		monitor.subTask(Policy.bind("CVSSSH2ServerConnection.open", location.getHost())); //$NON-NLS-1$		monitor.worked(1);		try {			String hostname = location.getHost();			String username = location.getUsername();			int port = location.getPort();			if (port == ICVSRepositoryLocation.USE_DEFAULT_PORT)				port = 0;			int retry = 1;			OutputStream channel_out;			InputStream channel_in;			while (true) {			  session = JSchSession.getSession(location, username, password, hostname, port, new JSchSession.ResponsiveSocketFacory(monitor));				channel = session.openChannel("exec"); //$NON-NLS-1$				((ChannelExec) channel).setCommand(COMMAND);				channel_out = channel.getOutputStream();				channel_in = channel.getInputStream();				try {					channel.connect();				} catch (JSchException ee) {				  retry--;				  if(retry<0){				    throw new CVSAuthenticationException(Policy.bind("CVSSSH2ServerConnection.3")); //$NON-NLS-1$				  }				  if(session.isConnected()){				    session.disconnect();				  }				  continue;				}				break;			}			inputStream = channel_in;			outputStream = channel_out;		} catch (JSchException e) {			if (e.toString().indexOf("invalid server's version string") == -1) { //$NON-NLS-1$				//e.printStackTrace();				throw new CVSAuthenticationException(e.toString());			}			throw new CVSAuthenticationException(e.toString());		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -