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