本文整理汇总了Java中org.apache.sshd.common.util.GenericUtils类的典型用法代码示例。如果您正苦于以下问题:Java GenericUtils类的具体用法?Java GenericUtils怎么用?Java GenericUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GenericUtils类属于org.apache.sshd.common.util包,在下文中一共展示了GenericUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: shuffleCase
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
public static String shuffleCase(CharSequence cs) {
if (GenericUtils.isEmpty(cs)) {
return "";
}
StringBuilder sb = new StringBuilder(cs.length());
for (int index = 0; index < cs.length(); index++) {
char ch = cs.charAt(index);
double v = Math.random();
if (Double.compare(v, 0.3d) < 0) {
ch = Character.toUpperCase(ch);
} else if ((Double.compare(v, 0.3d) >= 0) && (Double.compare(v, 0.6d) < 0)) {
ch = Character.toLowerCase(ch);
}
sb.append(ch);
}
return sb.toString();
}
开发者ID:termd,项目名称:termd,代码行数:20,代码来源:BaseTestSupport.java
示例2: deleteRecursive
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
/**
* Removes the specified file - if it is a directory, then its children
* are deleted recursively and then the directory itself. <B>Note:</B>
* no attempt is made to make sure that {@link File#delete()} was successful
*
* @param file The {@link File} to be deleted - ignored if {@code null}
* or does not exist anymore
* @return The <tt>file</tt> argument
*/
public static File deleteRecursive(File file) {
if ((file == null) || (!file.exists())) {
return file;
}
if (file.isDirectory()) {
File[] children = file.listFiles();
if (!GenericUtils.isEmpty(children)) {
for (File child : children) {
deleteRecursive(child);
}
}
}
// seems that if a file is not writable it cannot be deleted
if (!file.canWrite()) {
file.setWritable(true, false);
}
if (!file.delete()) {
System.err.append("Failed to delete ").println(file.getAbsolutePath());
}
return file;
}
开发者ID:termd,项目名称:termd,代码行数:35,代码来源:Utils.java
示例3: toFileSource
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
/**
* Converts a {@link URI} that may refer to an internal resource to
* a {@link File} representing is "source" container (e.g.,
* if it is a resource in a JAR, then the result is the JAR's path)
*
* @param uri The {@link URI} - ignored if {@code null}
* @return The matching {@link File}
* @throws MalformedURLException If source URI does not refer to a
* file location
* @see #getURLSource(URI)
*/
public static File toFileSource(URI uri) throws MalformedURLException {
String src = getURLSource(uri);
if (GenericUtils.isEmpty(src)) {
return null;
}
if (!src.startsWith(FILE_URL_PREFIX)) {
throw new MalformedURLException("toFileSource(" + src + ") not a '" + FILE_URL_SCHEME + "' scheme");
}
try {
return new File(new URI(src));
} catch (URISyntaxException e) {
throw new MalformedURLException("toFileSource(" + src + ")"
+ " cannot (" + e.getClass().getSimpleName() + ")"
+ " convert to URI: " + e.getMessage());
}
}
开发者ID:termd,项目名称:termd,代码行数:30,代码来源:Utils.java
示例4: getURLSource
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
/**
* @param externalForm The {@link URL#toExternalForm()} string - ignored if
* {@code null}/empty
* @return The URL(s) source path where {@link #JAR_URL_PREFIX} and
* any sub-resource are stripped
*/
public static String getURLSource(String externalForm) {
String url = externalForm;
if (GenericUtils.isEmpty(url)) {
return url;
}
url = stripJarURLPrefix(externalForm);
if (GenericUtils.isEmpty(url)) {
return url;
}
int sepPos = url.indexOf(RESOURCE_SUBPATH_SEPARATOR);
if (sepPos < 0) {
return adjustURLPathValue(url);
} else {
return adjustURLPathValue(url.substring(0, sepPos));
}
}
开发者ID:termd,项目名称:termd,代码行数:25,代码来源:Utils.java
示例5: waitForForwardingRequest
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
private void waitForForwardingRequest(String expected, long timeout) throws InterruptedException {
for (long remaining = timeout; remaining > 0L;) {
long waitStart = System.currentTimeMillis();
String actual = requestsQ.poll(remaining, TimeUnit.MILLISECONDS);
long waitEnd = System.currentTimeMillis();
if (GenericUtils.isEmpty(actual)) {
throw new IllegalStateException("Failed to retrieve request=" + expected);
}
if (expected.equals(actual)) {
return;
}
long waitDuration = waitEnd - waitStart;
remaining -= waitDuration;
}
throw new IllegalStateException("Timeout while waiting to retrieve request=" + expected);
}
开发者ID:termd,项目名称:termd,代码行数:20,代码来源:PortForwardingTest.java
示例6: create
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
@Override
public Command create() {
final SftpSubsystem subsystem = new SftpSubsystem(getExecutorService(), isShutdownOnExit(),
getUnsupportedAttributePolicy()) {
@Override
protected void setFileAttribute(final Path file, final String view, final String attribute,
final Object value, final LinkOption... options) throws IOException {
throw new UnsupportedOperationException("setFileAttribute Disabled");
}
@Override
protected void createLink(final int id, final String targetPath, final String linkPath,
final boolean symLink) throws IOException {
throw new UnsupportedOperationException("createLink Disabled");
}
};
final Collection<? extends SftpEventListener> listeners = getRegisteredListeners();
if (GenericUtils.size(listeners) > 0) {
for (final SftpEventListener l : listeners) {
subsystem.addSftpEventListener(l);
}
}
return subsystem;
}
开发者ID:ggrandes,项目名称:sftpserver,代码行数:25,代码来源:Server.java
示例7: AsyncUserAuthService
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
public AsyncUserAuthService(Session s) throws SshException {
ValidateUtils.checkTrue(s instanceof ServerSession, "Server side service used on client side");
if (s.isAuthenticated()) {
throw new SshException("Session already authenticated");
}
this.session = (ServerSession) s;
maxAuthRequests = session.getIntProperty(ServerFactoryManager.MAX_AUTH_REQUESTS, DEFAULT_MAX_AUTH_REQUESTS);
ServerFactoryManager manager = getFactoryManager();
userAuthFactories = new ArrayList<>(manager.getUserAuthFactories());
// Get authentication methods
authMethods = new ArrayList<>();
String mths = FactoryManagerUtils.getString(manager, ServerFactoryManager.AUTH_METHODS);
if (GenericUtils.isEmpty(mths)) {
for (NamedFactory<UserAuth> uaf : manager.getUserAuthFactories()) {
authMethods.add(new ArrayList<>(Collections.singletonList(uaf.getName())));
}
}
else {
for (String mthl : mths.split("\\s")) {
authMethods.add(new ArrayList<>(Arrays.asList(mthl.split(","))));
}
}
// Verify all required methods are supported
for (List<String> l : authMethods) {
for (String m : l) {
NamedFactory<UserAuth> factory = NamedResource.Utils.findByName(m, String.CASE_INSENSITIVE_ORDER, userAuthFactories);
if (factory == null) {
throw new SshException("Configured method is not supported: " + m);
}
}
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Authorized authentication methods: "+ NamedResource.Utils.getNames(userAuthFactories));
}
}
开发者ID:aeshell,项目名称:aesh-readline,代码行数:40,代码来源:AsyncUserAuthService.java
示例8: handleAuthenticationFailure
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
protected void handleAuthenticationFailure(int cmd, Buffer buffer) throws Exception {
String username = (currentAuth == null) ? null : currentAuth.getUsername();
ServerSession session = getServerSession();
if (log.isDebugEnabled()) {
log.debug("handleAuthenticationFailure({}@{}) {}",
username, session, SshConstants.getCommandMessageName(cmd));
}
StringBuilder sb = new StringBuilder((authMethods.size() + 1) * Byte.SIZE);
for (List<String> l : authMethods) {
if (GenericUtils.size(l) > 0) {
String m = l.get(0);
if (!UserAuthNoneFactory.NAME.equals(m)) {
if (sb.length() > 0) {
sb.append(",");
}
sb.append(m);
}
}
}
String remaining = sb.toString();
if (log.isDebugEnabled()) {
log.debug("handleAuthenticationFailure({}@{}) remaining methods: {}", username, session, remaining);
}
buffer = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_FAILURE, remaining.length() + Byte.SIZE);
buffer.putString(remaining);
buffer.putBoolean(false); // no partial success ...
session.writePacket(buffer);
if (currentAuth != null) {
try {
currentAuth.destroy();
} finally {
currentAuth = null;
}
}
}
开发者ID:termd,项目名称:termd,代码行数:40,代码来源:AsyncUserAuthService.java
示例9: repeat
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
public static String repeat(CharSequence csq, int nTimes) {
if (GenericUtils.isEmpty(csq) || (nTimes <= 0)) {
return "";
}
StringBuilder sb = new StringBuilder(nTimes * csq.length());
for (int index = 0; index < nTimes; index++) {
sb.append(csq);
}
return sb.toString();
}
开发者ID:termd,项目名称:termd,代码行数:13,代码来源:BaseTestSupport.java
示例10: parameterize
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
public static List<Object[]> parameterize(Collection<?> params) {
if (GenericUtils.isEmpty(params)) {
return Collections.emptyList();
}
List<Object[]> result = new ArrayList<Object[]>(params.size());
for (Object p : params) {
result.add(new Object[]{p});
}
return result;
}
开发者ID:termd,项目名称:termd,代码行数:13,代码来源:BaseTestSupport.java
示例11: assertListEquals
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
public static <E> void assertListEquals(String message, List<? extends E> expected, List<? extends E> actual) {
int expSize = GenericUtils.size(expected);
int actSize = GenericUtils.size(actual);
assertEquals(message + "[size]", expSize, actSize);
for (int index = 0; index < expSize; index++) {
E expValue = expected.get(index);
E actValue = actual.get(index);
assertEquals(message + "[" + index + "]", expValue, actValue);
}
}
开发者ID:termd,项目名称:termd,代码行数:12,代码来源:BaseTestSupport.java
示例12: assertMapEquals
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
public static <K, V> void assertMapEquals(String message, Map<? extends K, ? extends V> expected, Map<? super K, ? extends V> actual) {
int numItems = GenericUtils.size(expected);
assertEquals(message + "[size]", numItems, GenericUtils.size(actual));
if (numItems > 0) {
for (Map.Entry<? extends K, ? extends V> ee : expected.entrySet()) {
K key = ee.getKey();
V expValue = ee.getValue();
V actValue = actual.get(key);
assertEquals(message + "[" + key + "]", expValue, actValue);
}
}
}
开发者ID:termd,项目名称:termd,代码行数:14,代码来源:BaseTestSupport.java
示例13: resolve
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
public static Path resolve(Path root, String... children) {
if (GenericUtils.isEmpty(children)) {
return root;
} else {
return resolve(root, Arrays.asList(children));
}
}
开发者ID:termd,项目名称:termd,代码行数:8,代码来源:Utils.java
示例14: getClassContainerLocationURL
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
/**
* @param clazz A {@link Class} object
* @return A {@link URL} to the location of the class bytes container
* - e.g., the root folder, the containing JAR, etc.. Returns
* {@code null} if location could not be resolved
*/
public static URL getClassContainerLocationURL(Class<?> clazz) {
ProtectionDomain pd = clazz.getProtectionDomain();
CodeSource cs = (pd == null) ? null : pd.getCodeSource();
URL url = (cs == null) ? null : cs.getLocation();
if (url == null) {
url = getClassBytesURL(clazz);
if (url == null) {
return null;
}
String srcForm = getURLSource(url);
if (GenericUtils.isEmpty(srcForm)) {
return null;
}
try {
url = new URL(srcForm);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("getClassContainerLocationURL(" + clazz.getName() + ")"
+ " Failed to create URL=" + srcForm + " from " + url.toExternalForm()
+ ": " + e.getMessage());
}
}
return url;
}
开发者ID:termd,项目名称:termd,代码行数:33,代码来源:Utils.java
示例15: stripJarURLPrefix
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
public static String stripJarURLPrefix(String externalForm) {
String url = externalForm;
if (GenericUtils.isEmpty(url)) {
return url;
}
if (url.startsWith(JAR_URL_PREFIX)) {
return url.substring(JAR_URL_PREFIX.length());
}
return url;
}
开发者ID:termd,项目名称:termd,代码行数:13,代码来源:Utils.java
示例16: getClassBytesResourceName
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
/**
* @param name The fully qualified class name - ignored if {@code null}/empty
* @return The relative path of the class file byte-code resource
*/
public static String getClassBytesResourceName(String name) {
if (GenericUtils.isEmpty(name)) {
return name;
} else {
return new StringBuilder(name.length() + CLASS_FILE_SUFFIX.length())
.append(name.replace('.', '/'))
.append(CLASS_FILE_SUFFIX)
.toString();
}
}
开发者ID:termd,项目名称:termd,代码行数:15,代码来源:Utils.java
示例17: findThreads
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
private Set<Thread> findThreads(ThreadGroup group, String name) {
int numThreads = group.activeCount();
Thread[] threads = new Thread[numThreads * 2];
numThreads = group.enumerate(threads, false);
Set<Thread> ret = new HashSet<Thread>();
// Enumerate each thread in `group'
for (int i = 0; i < numThreads; ++i) {
Thread t = threads[i];
// Get thread
// log.debug("Thread name: " + threads[i].getName());
if (checkThreadForPortForward(t, name)) {
ret.add(t);
}
}
// didn't find the thread to check the
int numGroups = group.activeGroupCount();
ThreadGroup[] groups = new ThreadGroup[numGroups * 2];
numGroups = group.enumerate(groups, false);
for (int i = 0; i < numGroups; ++i) {
ThreadGroup g = groups[i];
Collection<Thread> c = findThreads(g, name);
if (GenericUtils.isEmpty(c)) {
continue; // debug breakpoint
}
ret.addAll(c);
}
return ret;
}
开发者ID:termd,项目名称:termd,代码行数:30,代码来源:PortForwardingTest.java
示例18: AsyncUserAuthService
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
public AsyncUserAuthService(Session s) throws SshException {
ValidateUtils.checkTrue(s instanceof ServerSession, "Server side service used on client side");
if (s.isAuthenticated()) {
throw new SshException("Session already authenticated");
}
serverSession = (ServerSession) s;
maxAuthRequests = PropertyResolverUtils.getIntProperty(s, ServerAuthenticationManager.MAX_AUTH_REQUESTS, ServerAuthenticationManager.DEFAULT_MAX_AUTH_REQUESTS);
List<NamedFactory<UserAuth>> factories = ValidateUtils.checkNotNullAndNotEmpty(
serverSession.getUserAuthFactories(), "No user auth factories for %s", s);
userAuthFactories = new ArrayList<>(factories);
// Get authentication methods
authMethods = new ArrayList<>();
String mths = PropertyResolverUtils.getString(s, ServerFactoryManager.AUTH_METHODS);
if (GenericUtils.isEmpty(mths)) {
for (NamedFactory<UserAuth> uaf : factories) {
authMethods.add(new ArrayList<>(Collections.singletonList(uaf.getName())));
}
} else {
if (log.isDebugEnabled()) {
log.debug("ServerUserAuthService({}) using configured methods={}", s, mths);
}
for (String mthl : mths.split("\\s")) {
authMethods.add(new ArrayList<>(Arrays.asList(GenericUtils.split(mthl, ','))));
}
}
// Verify all required methods are supported
for (List<String> l : authMethods) {
for (String m : l) {
NamedFactory<UserAuth> factory = NamedResource.Utils.findByName(m, String.CASE_INSENSITIVE_ORDER, userAuthFactories);
if (factory == null) {
throw new SshException("Configured method is not supported: " + m);
}
}
}
if (log.isDebugEnabled()) {
log.debug("ServerUserAuthService({}) authorized authentication methods: {}",
s, NamedResource.Utils.getNames(userAuthFactories));
}
}
开发者ID:termd,项目名称:termd,代码行数:44,代码来源:AsyncUserAuthService.java
示例19: setUp
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
sshd = setupTestServer();
PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048);
PropertyResolverUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, 256);
sshd.setTcpipForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
sshd.start();
if (!requestsQ.isEmpty()) {
requestsQ.clear();
}
final TcpipForwarderFactory factory = ValidateUtils.checkNotNull(sshd.getTcpipForwarderFactory(), "No TcpipForwarderFactory");
sshd.setTcpipForwarderFactory(new TcpipForwarderFactory() {
private final Class<?>[] interfaces = {TcpipForwarder.class};
private final Map<String, String> method2req = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) {
private static final long serialVersionUID = 1L; // we're not serializing it...
{
put("localPortForwardingRequested", TcpipForwardHandler.REQUEST);
put("localPortForwardingCancelled", CancelTcpipForwardHandler.REQUEST);
}
};
@Override
public TcpipForwarder create(ConnectionService service) {
Thread thread = Thread.currentThread();
ClassLoader cl = thread.getContextClassLoader();
final TcpipForwarder forwarder = factory.create(service);
return (TcpipForwarder) Proxy.newProxyInstance(cl, interfaces, new InvocationHandler() {
@SuppressWarnings("synthetic-access")
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result = method.invoke(forwarder, args);
String name = method.getName();
String request = method2req.get(name);
if (GenericUtils.length(request) > 0) {
if (requestsQ.offer(request)) {
log.info("Signal " + request);
} else {
log.error("Failed to offer request=" + request);
}
}
return result;
}
});
}
});
sshPort = sshd.getPort();
NioSocketAcceptor acceptor = new NioSocketAcceptor();
acceptor.setHandler(new IoHandlerAdapter() {
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
IoBuffer recv = (IoBuffer) message;
IoBuffer sent = IoBuffer.allocate(recv.remaining());
sent.put(recv);
sent.flip();
session.write(sent);
}
});
acceptor.setReuseAddress(true);
acceptor.bind(new InetSocketAddress(0));
echoPort = acceptor.getLocalAddress().getPort();
this.acceptor = acceptor;
}
开发者ID:termd,项目名称:termd,代码行数:68,代码来源:PortForwardingTest.java
示例20: testRemoteForwardingWithDisconnect
import org.apache.sshd.common.util.GenericUtils; //导入依赖的package包/类
@Test(timeout = 45000)
public void testRemoteForwardingWithDisconnect() throws Exception {
Session session = createSession();
try {
// 1. Create a Port Forward
int forwardedPort = Utils.getFreePort();
session.setPortForwardingR(forwardedPort, TEST_LOCALHOST, echoPort);
waitForForwardingRequest(TcpipForwardHandler.REQUEST, TimeUnit.SECONDS.toMillis(5L));
// 2. Establish a connection through it
try (Socket s = new Socket(TEST_LOCALHOST, forwardedPort)) {
s.setSoTimeout((int) TimeUnit.SECONDS.toMillis(10L));
// 3. Simulate the client going away
rudelyDisconnectJschSession(session);
// 4. Make sure the NIOprocessor is not stuck
Thread.sleep(TimeUnit.SECONDS.toMillis(1L));
// from here, we need to check all the threads running and find a
// "NioProcessor-"
// that is stuck on a PortForward.dispose
ThreadGroup root = Thread.currentThread().getThreadGroup().getParent();
while (root.getParent() != null) {
root = root.getParent();
}
for (int index = 0;; index++) {
Collection<Thread> pending = findThreads(root, "NioProcessor-");
if (GenericUtils.size(pending) <= 0) {
log.info("Finished after " + index + " iterations");
break;
}
try {
Thread.sleep(TimeUnit.SECONDS.toMillis(1L));
} catch (InterruptedException e) {
// ignored
}
}
session.delPortForwardingR(forwardedPort);
}
} finally {
session.disconnect();
}
}
开发者ID:termd,项目名称:termd,代码行数:46,代码来源:PortForwardingTest.java
注:本文中的org.apache.sshd.common.util.GenericUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论