小编Alv*_*ins的帖子

SFTP服务器在Apache Mina SSHD中设置用户/密码

我正在使用此示例,取自Java SFTP Server Library?:

public void setupSftpServer(){
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setPort(22);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));

    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
    userAuthFactories.add(new UserAuthNone.Factory());
    sshd.setUserAuthFactories(userAuthFactories);

    sshd.setCommandFactory(new ScpCommandFactory());

    List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
    namedFactoryList.add(new SftpSubsystem.Factory());
    sshd.setSubsystemFactories(namedFactoryList);

    try {
        sshd.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

但我需要为SFTP服务器设置用户登录和pw.我怎样才能做到这一点?谢谢

java sftp apache-mina

11
推荐指数
1
解决办法
4926
查看次数

ConcurrentModificationException仅在Java 1.8.0_45中

我对这段代码有两个疑问:

import java.util.*;

public class TestClass {

    private static List<String> list;   
    public static void main(String[] argv) {

        list = generateStringList(new Random(), "qwertyuioasdfghjklzxcvbnmPOIUYTREWQLKJHGFDSAMNBVCXZ1232456789", 50, 1000);

//      Collections.sort(list, new Comparator<String>() {
//          public int compare(String f1, String f2) {
//              return -f1.compareTo(f2);
//          }
//      });

        for (int i = 0; i < 500; i++) {
            new MyThread(i).start();
         }

    }

    private static class MyThread extends Thread  {
        int id;
        MyThread(int id) { this.id = id; }
        public void run() {

            Collections.sort(list, new …
Run Code Online (Sandbox Code Playgroud)

java concurrency

4
推荐指数
1
解决办法
4805
查看次数

检查对象是否为Matrix

我需要测试一个Object是Matrix还是Array.

比如我有:

String[] array;
String[][] matrix;
Run Code Online (Sandbox Code Playgroud)

我正在使用:

private boolean isVector(Class<?> clazz) {
    return clazz.isArray();
}
private boolean isMatrix(Class<?> clazz) {
    return clazz.getSimpleName().endsWith("[][]");
}
Run Code Online (Sandbox Code Playgroud)

但我不想使用,clazz.getSimpleName()因为非常慢(根据JProfiler,我的执行时间的近10%),是否有另一种方法来测试Object是否是一个矩阵?

我不能使用instanceof,因为它可以是任何对象的矩阵.

java reflection

1
推荐指数
1
解决办法
61
查看次数

标签 统计

java ×3

apache-mina ×1

concurrency ×1

reflection ×1

sftp ×1