本文整理汇总了Java中org.apache.sshd.common.util.GenericUtils.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java GenericUtils.isEmpty方法的具体用法?Java GenericUtils.isEmpty怎么用?Java GenericUtils.isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sshd.common.util.GenericUtils
的用法示例。
在下文中一共展示了GenericUtils.isEmpty方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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;
}
示例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());
}
}
示例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));
}
}
示例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);
}
示例6: 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));
}
}
示例7: 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();
}
示例8: 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;
}
示例9: 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));
}
}
示例10: 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;
}
示例11: 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;
}
示例12: 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();
}
}
示例13: 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;
}
示例14: 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));
}
}