Springboot整合Jsch-Sftp

背景

??開發一個基于jsch的sftp工具類,方便在以后的項目中使用。寫代碼的過程記錄下來,作為備忘錄。。。

Maven依賴

  • springboot依賴
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.0</version>
</parent>
  • jsch依賴
 <dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.55</version>
</dependency>
  • 完整依賴
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>jsch-sftp</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.0</version></parent><dependencies><!-- web應用相關 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- 單元測試 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId></dependency><!-- jsch SFTP --><dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.55</version></dependency><!-- lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies></project>

項目結構

在這里插入圖片描述

Sftp連接工具類

  • JschSftpRun: 項目啟動類
package cn.com.soulfox;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;/*** 啟動類** @author xxxx* @create 2024/7/5 11:50*/
@SpringBootApplication
public class JschSftpRun {public static void main(String[] args) {ConfigurableApplicationContext context = SpringApplication.run(JschSftpRun.class, args);}
}
  • JschSftpConneciton: 創建sftp連接工具類
    ??用于創建sftp連接,類中提供了創建sftp連接的方法,另外還提供了在創建sftp連接失敗后,重新嘗試創建連接的方法
package cn.com.soulfox.jsch;import com.jcraft.jsch.*;
import lombok.extern.slf4j.Slf4j;/*** @author xxxx* @create 2024/7/4 12:15*/
@Slf4j
public class JschSftpConneciton {private static final String SFTP_PROTOCOL = "sftp";private static final Integer DEFAULT_RETRY_COUNT_5 = 5;private static final Long SLEEP_ITME_1000 = 1000L;//每次重試的時間間隔private String host;private Integer port;private String username;private String password;private Integer sessionTimeout;private Integer connectionTimeout;public JschSftpConneciton setHost(String host) {this.host = host;return this;}public JschSftpConneciton setPort(Integer port) {this.port = port;return this;}public JschSftpConneciton setUsername(String username) {this.username = username;return this;}public JschSftpConneciton setPassword(String password) {this.password = password;return this;}public JschSftpConneciton setSessionTimeout(Integer sessionTimeout) {this.sessionTimeout = sessionTimeout;return this;}public JschSftpConneciton setConnectionTimeout(Integer connectionTimeout) {this.connectionTimeout = connectionTimeout;return this;}/*** 返回SftpWrapper對象,是為了方便釋放Session,Channel,ChannelSftp資源* SFTP連接服務器*/public SftpWrapper connect() throws  Exception {JSch jsch = new JSch();Session session = null;Channel channel = null;ChannelSftp sftp = null;try {session = jsch.getSession(username, host, port);if (session == null) {throw new JSchException("create session error");}//設置登陸主機的密碼session.setPassword(password);//設置第一次登陸的時候提示,可選值:(ask | yes | no)session.setConfig("StrictHostKeyChecking", "no");//設置登陸超時時間session.connect(sessionTimeout);session.sendKeepAliveMsg();//創建sftp通信通道channel = session.openChannel(SFTP_PROTOCOL);channel.connect(connectionTimeout);sftp = (ChannelSftp) channel;return new SftpWrapper(session, channel, sftp);}catch (JSchException e){log.error("SFTP連接異常:", e);if (sftp != null ) {sftp.disconnect();}if (channel != null ) {channel.disconnect();}if (session != null ) {session.disconnect();}throw e;} catch (Exception e1) {log.error("SFTP連接異常:", e1);if (sftp != null ) {sftp.disconnect();}if (channel != null ) {channel.disconnect();}if (session != null ) {session.disconnect();}throw e1;}}/*** 獲取sftp連接,獲取連接失敗時會重試,* 默認重試次數:5次* @return* @throws Exception*/public SftpWrapper connectWithRetry() throws Exception {return connectWithRetry(DEFAULT_RETRY_COUNT_5);}public SftpWrapper connectWithRetry(int retryCount) throws Exception {//最大重試次數int maxRetryCount = DEFAULT_RETRY_COUNT_5;if(retryCount > 0){maxRetryCount = retryCount;}int retry = 0;Throwable t = null;do {try {SftpWrapper channelSftpWrapper = this.connect();if(channelSftpWrapper != null){t = null;return channelSftpWrapper;}} catch (Exception e) {t = e;}try {Thread.sleep(SLEEP_ITME_1000);//休息1秒} catch (InterruptedException e) {}}while (retry++ < maxRetryCount);if(t != null){throw new Exception(t);}return null;}}
  • SftpWrapper: sftp連接對象包裝類,屬性包括Session,Channel,ChannelSftp
    ??執行sftp操作有ChannelSftp就可以了,使用Sftp包裝類,是為了方便關閉資源
package cn.com.soulfox.jsch;import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.Session;
import lombok.AllArgsConstructor;
import lombok.Data;/*** SftpWrapper類簡單包裝ChannelSftl對象,方便關閉資源* @author xxxx* @create 2024/7/4 14:26*/
@AllArgsConstructor//生成全字段,構造方法
@Data //生成 getter,setter方法
public class SftpWrapper {private Session session = null;private Channel channel = null;private ChannelSftp sftp = null;/*** 關閉資源*/public void disconnect() {if (sftp != null && sftp.isConnected()) {sftp.disconnect();}if (channel != null && channel.isConnected()) {channel.disconnect();}if (session != null && session.isConnected()) {session.disconnect();}}
}
  • JschSftpConfig: jsch sftp配置類
    ??初始化 jsch sftp
package cn.com.soulfox.config;import cn.com.soulfox.jsch.JschSftpConneciton;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;/*** @author xxxx* @create 2024/7/4 12:12*/
@Configuration
public class JschSftpConfig {@Value("${jsch.sftp.host}")private String host;@Value("${jsch.sftp.port:22}")private Integer port;@Value("${jsch.sftp.username}")private String username;@Value("${jsch.sftp.password}")private String password;@Value("${jsch.sftp.session-timeout:60000}")private Integer sessionTimeout;//單位毫秒@Value("${jsch.sftp.connect-timeout:5000}")private Integer connectTimeout;//單位毫秒@Bean@Lazypublic JschSftpConneciton jschSftpConneciton(){return new JschSftpConneciton().setHost(host).setPort(port).setUsername(username).setPassword(password).setSessionTimeout(sessionTimeout).setConnectionTimeout(connectTimeout);}}

sftp連接信息配置在文件application.yml里
jsch:
sftp:
host: 172.168.xxx.xx
port: 1221 #默認22,1221公司自己定義的,這里要配置正確
username: xxxx #遠程服務器用戶名
password: xxxx #遠程服務器密碼
sftp連接信息

SftpUitl 工具類,提供下載,上傳文件功能

package cn.com.soulfox.jsch;import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import java.io.*;/*** @author xxxx* @create 2024/7/4 14:28*/
@Component
@Slf4j
public class JschSftpUtil {private static JschSftpConneciton jschSftpConneciton;@Autowiredpublic void setJschSftpConneciton(JschSftpConneciton jschSftpConneciton) {JschSftpUtil.jschSftpConneciton = jschSftpConneciton;}/*** 下載文件* @param remotePath            遠程目錄* @param downloadFileName      待下載的遠程文件名稱* @param localSavePath         下載文件保存的本地目錄*/public static void downloadFile(String remotePath, String downloadFileName, String localSavePath) {SftpWrapper sftpWrapper = null;try {//sftp連接對象sftpWrapper = jschSftpConneciton.connectWithRetry();//進入遠程服務器指定的目錄sftpWrapper.getSftp().cd(remotePath);if (!checkLocalPath(localSavePath)) {log.info("本地目錄[{}]不存在,且新建失敗+++++", localSavePath);return;}String localFile = checkPathEnd(localSavePath) + downloadFileName;File outFile = new File(localFile);sftpWrapper.getSftp().get(downloadFileName, new FileOutputStream(outFile));log.info("從遠程目錄[{}]下載文件[{}]到本地目錄[{}]成功", remotePath, downloadFileName, localSavePath);} catch (SftpException e) {log.info("從遠程目錄[{}]下載文件[{}]到本地目錄[{}]失敗", remotePath, downloadFileName, localSavePath);log.error("下載文件失敗: ", e);} catch (Exception e) {log.info("從遠程目錄[{}]下載文件[{}]到本地目錄[{}]失敗", remotePath, downloadFileName, localSavePath);log.error("下載文件失敗: ", e);} finally {if (sftpWrapper != null) {sftpWrapper.disconnect();}}}/**** @param localDir              保存上傳文件的本地目錄* @param uploadFileName        上傳文件名稱* @param remoteSaveDir         保存上傳文件的遠程目錄, 建議使用絕對路徑*                              如果使用相對路徑,建議基準目錄使用sfpt登錄后所在的目錄*                              這個目錄,使用channelSftp.goHome()可以獲取*/public static void uploadFile(String localDir, String uploadFileName, String remoteSaveDir) {String uploadFilePath = checkPathEnd(localDir) + uploadFileName;File uploadFile = new File(uploadFilePath);uploadFile(uploadFile, remoteSaveDir);}/*** 上傳文件* @param uploadFilePath        本地文件的路徑* @param remoteSaveDir         保存上傳文件的遠程目錄, 建議使用絕對路徑*                              如果使用相對路徑,建議基準目錄使用sfpt登錄后所在的目錄*                              這個目錄,使用channelSftp.goHome()可以獲取*/public static void uploadFile(String uploadFilePath, String remoteSaveDir) {File uploadFile = new File(uploadFilePath);uploadFile(uploadFile, remoteSaveDir);}/*** 上傳文件* @param uploadFile        上傳文件的File對象* @param remoteSavePath    保存上傳文件的遠程目錄, 建議使用絕對路徑*                          如果使用相對路徑,建議基準目錄使用sfpt登錄后所在的目錄*                          這個目錄,使用channelSftp.goHome()可以獲取*/public static void uploadFile(File uploadFile, String remoteSavePath) {if(uploadFile == null ){log.info("本地文件對象不存在++++");return;}if(!uploadFile.exists()){log.info("本地文件[{}]不存在", uploadFile.getAbsoluteFile());return;}InputStream is = null;try {is = new FileInputStream(uploadFile);} catch (FileNotFoundException e) {log.info("獲取本地文件[{}]的文件流失敗", uploadFile.getAbsoluteFile());log.error("獲取文件流失敗: ", e);if(is != null){try {is.close();} catch (IOException ioException) {}}return;}SftpWrapper sftpWrapper = null;try {//sftp連接對象sftpWrapper = jschSftpConneciton.connectWithRetry();//檢查遠程目錄,不存在則創建createLinuxRemoteDirs(sftpWrapper.getSftp(), remoteSavePath);//進入用戶home目錄,sftpWrapper.getSftp().cd(sftpWrapper.getSftp().getHome());//保證當前目錄在上傳文件保存的目錄sftpWrapper.getSftp().cd(remoteSavePath);//上傳文件sftpWrapper.getSftp().put(is, uploadFile.getName());} catch (SftpException e) {log.info("上傳本地文件[{}]到遠程目錄[{}]失敗", uploadFile.getAbsoluteFile(), remoteSavePath);log.error("上傳本地文件失敗: ", e);} catch (Exception e) {log.info("上傳本地文件[{}]到遠程目錄[{}]失敗", uploadFile.getAbsoluteFile(), remoteSavePath);log.error("上傳本地文件失敗: ", e);} finally {if (sftpWrapper != null) {sftpWrapper.disconnect();}if(is != null){try {is.close();} catch (IOException e) {}}}}/*** 檢查目錄結是否以目錄分隔符結尾* 如果不是,則加上目錄分隔符結尾** @param localPath 本地目錄* @return*/private static String checkPathEnd(String localPath) {if (localPath.endsWith("/") || localPath.endsWith("\\")) {return localPath;}return localPath + File.separator;}/*** 檢查本地目錄是否存在,不存在就創建。* 為了防止其他線程已創建目錄,加上了重試代碼** @param localPath 本地目錄* @return*/private static boolean checkLocalPath(String localPath) {int maxRetryCount = 5;int retry = 0;do {File localDir = new File(localPath);if (localDir.exists()) {return true;}boolean result = localDir.mkdirs();if (result) {return true;}try {Thread.sleep(1000L);//休息1秒} catch (InterruptedException e) {}} while (retry++ < maxRetryCount);return false;}/*** 檢查和創建[ linux系統 ]的遠程多級目錄,* 外部調用, 單純的創建遠程目錄,不作其他操作* @param remoteDir     遠程目錄* @throws SftpException*/public static void createLinuxRemoteDirs( String remoteDir) throws SftpException {SftpWrapper sftpWrapper = null;try {sftpWrapper = jschSftpConneciton.connectWithRetry();createLinuxRemoteDirs(sftpWrapper.getSftp(), remoteDir);} catch (SftpException e) {log.info("創建Linux遠程目錄[{}]失敗", remoteDir);log.error("創建Linux遠程目錄失敗: ", e);} catch (Exception e) {log.info("創建Linux遠程目錄[{}]失敗", remoteDir);log.error("創建Linux遠程目錄失敗: ", e);} finally {if (sftpWrapper != null) {sftpWrapper.disconnect();}}}/*** 檢查和創建[ linux系統 ]的遠程多級目錄,* linux系統目錄分隔符是 “/”* 內部上傳文件的方法調用** @param sftpChannel* @param remoteDir  遠程目錄* @throws SftpException*/public static void createLinuxRemoteDirs(ChannelSftp sftpChannel, String remoteDir) throws SftpException {if(remoteDir == null || "".equals(remoteDir)){log.info("待創建的遠程目錄為空++++++++");return;}String[] dirs = remoteDir.split("/");;if(dirs == null || dirs.length == 0){log.info("拆分目錄[{}]失敗,沒有獲取到目錄數組", remoteDir);return;}//進入用戶home目錄,保證初始目錄正確sftpChannel.cd(sftpChannel.getHome());if( dirs.length == 1){//只有一層目錄,直接處理try {sftpChannel.cd(dirs[0]);} catch (SftpException e) {if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {log.info("開始創建遠程目錄[{}]", dirs[0]);sftpChannel.mkdir(dirs[0]);} else {throw e;}}return;}StringBuilder sb = new StringBuilder();//處理第一個元素if(remoteDir.startsWith(".")){//相對路徑,把缺少的路徑補上sb.append(sftpChannel.getHome()).append("/");}else if(remoteDir.startsWith("/")){//絕對路徑,把"/"放到目錄開頭sb.append("/");}else {//既不是”/“開頭,也不是”.“開頭//屬于相對路徑的一種情況try {//先處理第一層目錄sftpChannel.cd(dirs[0]);} catch (SftpException e) {if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {log.info("開始創建遠程目錄[{}]", dirs[0]);sftpChannel.mkdir(dirs[0]);} else {throw e;}}//把已處理的目錄加上sb.append(sftpChannel.getHome()).append("/").append(dirs[0]).append("/");}//從第二個元素開始創建不存在的目錄for (int i = 1; i < dirs.length; i++) {String dir = dirs[i];if (dir.isEmpty() ) {//跳過空字符串continue;}sb.append(dir + "/");try {sftpChannel.cd(sb.toString());} catch (SftpException e) {if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {log.info("開始創建遠程目錄[{}]", sb.toString());sftpChannel.mkdir(sb.toString());} else {throw e;}}}
//        for (String dir : dirs) {
//            if (dir.isEmpty() || dir.contains(".")) {
//                //跳過空字符串,和"."字符串
//                continue;
//            }
//            sb.append(dir + "/");
//            try {
//                sftpChannel.cd(sb.toString());
//            } catch (SftpException e) {
//                if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
//                    sftpChannel.mkdir(sb.toString());
//                } else {
//                    throw e;
//                }
//            }
//        }}
}

單元測試

  • JschSftpConfigTest: 測試類
package cn.com.soulfox.config;import cn.com.soulfox.JschSftpRun;
import cn.com.soulfox.jsch.JschSftpConneciton;
import cn.com.soulfox.jsch.JschSftpUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;/*** @author xxxx* @create 2024/7/5 12:57*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = JschSftpRun.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class JschSftpConfigTest {@Autowiredprivate JschSftpConneciton sftpConneciton;/*** 下載文件*/@Testpublic void testDownload(){//從遠程服務器上的下載 /home/jiyh/ 目錄下的 testabc.txt//下載文件保存到 d:\jiyhString remotePath = "/home/jiyh/";String downloadFileName = "testabc.txt";String localSavePath = "d:\\jiyh";JschSftpUtil.downloadFile(remotePath, downloadFileName, localSavePath);}/*** 上傳文件*/@Testpublic void testUpload(){//上傳傳本地 d:\jiyh 目錄下的 test123.txt文件//到遠程 /home/jiyh/test/test 目錄//目錄不存在,會自動創建JschSftpUtil.uploadFile("d:\\jiyh", "test123.txt", "/home/jiyh/test/test");}
}
  • 在遠程服務器準備測試文件 文件內容隨便,這里我準備的內容為“112dadfdefee”
    在這里插入圖片描述

  • 測試下載功能
    測試結果:
    在這里插入圖片描述

  • 測試上傳功能 :在本地 d:/jiyh 目錄準備測試文件“test123.txt”,內容為“dfdfdfdfdaerwrt”
    測試結果
    在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/41835.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/41835.shtml
英文地址,請注明出處:http://en.pswp.cn/web/41835.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

codeforces 1633A

文章目錄 1. 題目鏈接2. 題目代碼正確代碼錯誤代碼 3. 題目總結 1. 題目鏈接 Div. 7 2. 題目代碼 正確代碼 #include<iostream> using namespace std; int main(){int testCase;cin >> testCase;while(testCase --){int ingeter;cin >> ingeter;if(!(inget…

SpringBoot彩蛋之定制啟動畫面

寫在前面 在日常開發中&#xff0c;我們經常會看到各種各樣的啟動畫面。例如以下幾種 ① spring項目啟動畫面 ② mybatisplus啟動畫面 ③若依項目啟動畫面 還有很多各式各樣好看的啟動畫面&#xff0c;那么怎么定制這些啟動畫面呢&#xff1f; 一、小試牛刀 ① 新建一個Spr…

Java 8 到 Java 22 新特性詳解

Java 8 到 Java 22 新特性詳解 Java自發布以來一直在不斷演進&#xff0c;添加新特性以提升開發效率和性能。本文將介紹Java 8到Java 22的主要新特性&#xff0c;幫助開發者了解各版本的新功能和改進。 Java 8 (2014) 1. Lambda 表達式 Lambda 表達式允許使用簡潔的語法定義…

SQL 之 concat_ws和concat的區別

concat_ws和concat都是用于連接字符串的函數&#xff0c;但它們在使用上有一些區別&#xff1a; 一、concat、concat_ws函數格式&#xff1a; concat格式&#xff1a; concat&#xff08;參數1,參數2,…參數n&#xff09;&#xff0c;如果要加’分隔符’直接寫在 各參數中間就…

關于微信支付-商戶平臺:查詢訂單提示“查詢失敗:操作失敗,請稍候重試”的分析

目錄 引子 分析 應對 小結 引子 在開發和實施微信 JSAPI 支付的應用后&#xff0c;我們遇到了一些問題&#xff0c;訂單的狀態更新不正常&#xff0c;當然我們首先需要從自身尋找原因和完善解決問題的辦法和方案。在支付的過程中&#xff0c;客戶會給我們一些反饋&#xf…

Open-Sora1.2環境搭建推理測試

引子 前陣子寫了一篇Open-Sora1.0環境搭建&推理測試&#xff08;Open-Sora1.0環境搭建&推理測試_自己搭建sora服務-CSDN博客&#xff0c;感興趣的童鞋&#xff0c;請移步&#xff09;。Open-Sora1.1發布的時候&#xff0c;撇了一眼新聞。后面一轉頭&#xff0c;忘記這…

ARL聯動AWVS實現自動化漏洞掃描

0x01 前言 很多場景下需要大范圍的掃描漏洞和快速排查互聯網暴露面的漏洞&#xff0c;需要使用這種自動化的手段&#xff0c;常規滲透測試的找互聯網暴露面是&#xff0c;域名>子域名>IP>C段>端口&#xff0c;可以手動收集&#xff0c;也可以借助一些網絡搜索引擎…

css中偽元素 :: before的用法

在CSS中&#xff0c;偽元素 ::before 用于在選定元素的內容前插入內容。它常用于添加圖標、文本或裝飾性的元素&#xff0c;而不需要在HTML中實際添加額外的標簽。 以下是一個示例說明 ::before 的用法&#xff1a; <!DOCTYPE html> <html lang"en"> &…

一文解決Postman請求發送難題

標題&#xff1a;【技術深度解析】一文解決Postman請求發送難題 在API開發和測試過程中&#xff0c;Postman作為一款強大的工具&#xff0c;其重要性不言而喻。然而&#xff0c;開發者們時常會遇到Postman無法發送請求的問題&#xff0c;這無疑會嚴重影響開發進度和測試效率。…

wordpress網站添加一個臨時維護功能

把以下代碼放到functions.php文件中&#xff0c;主要用網站臨時維護或者用于備案。事情做好了&#xff0c;把以下代碼刪除即可&#xff01;&#xff01;&#xff01; 有時遇到一些情況&#xff0c;比如站點需要閉站備案、或者被要求停站等等&#xff0c;我們就可以使用本文的功…

開發個人Go-ChatGPT--5 模型管理 (三)

開發個人Go-ChatGPT–5 模型管理 (三) 服務部署 go-ChatGPT項目涉及的中間件服務較多&#xff0c;以下部署文件目錄&#xff1a; |-- chat-api | |-- etc | | -- config.yaml | -- logs |-- chat-rpc | |-- etc | | -- config.yaml | -- logs |-- docker-co…

CP AUTOSAR標準之UDPNetworkManagement(AUTOSAR_CP_SWS_UDPNetworkManagement)(更新中……)

1 簡介和功能概述 本文檔介紹了AUTOSAR UDP網絡管理(UdpNm)的概念、核心功能、可選功能、接口和配置問題。UdpNm旨在成為一項可選功能。它旨在與TCP/IP堆棧協同工作,獨立于所用通信系統的物理層。AUTOSAR UDP網絡管理是一種獨立于硬件的協議,可用于基于TCP/IP的系統(有關限制…

卡爾曼濾波Q和R怎么調

卡爾曼濾波器是一種有效的估計算法&#xff0c;主要用于在存在噪聲的環境中估計動態系統的狀態。它通過結合預測模型&#xff08;系統動態&#xff09;和觀測數據&#xff08;包括噪聲&#xff09;來實現這一點。在卡爾曼濾波中&#xff0c;調整過程噪聲協方差矩陣 ( Q ) 和測量…

Java中的標準輸入流簡述

System.in簡介 System.in 是標準輸入流&#xff0c;通常與鍵盤輸入相關聯。它是 InputStream 類型的對象&#xff0c;Java 使用它來從控制臺接收用戶輸入。在 Java 程序中&#xff0c;通常使用 Scanner 類來讀取 System.in 的輸入。 以下是一些關鍵點&#xff0c;解釋為什么需…

Kubernetes運維工程師必備:K8s 基礎面試題精編(一)

Kubernetes運維工程師必備:K8s 基礎面試題精編(一) 1. 什么是Kubernetes?2. Kubernetes如何實現容器編排?3. 說出k8s的常見資源對象?4. 什么是pod?5. Deployment介紹及使用?6. statefulesets介紹及使用?7. statefulesets和deployment區別?8. 什么是調度器(Scheduler…

The First項目報告:NvirWorld與區塊鏈游戲的未來

根據官方公告&#xff0c;The Fisrt現貨區將于2024年7月2日16:00上架NVIR/USDT交易對&#xff0c;NVIR是NvirWorld平臺的原生代幣。作為一個去中心化解決方案&#xff0c;NvirWorld為開發者提供了一個簡化且適應性強的環境&#xff0c;旨在通過優化的擴展解決方案來降低交易成本…

docker 本地部署大模型(ollama)

docker 安裝 ollama docker search ollama docker pull ollama/ollama###docker下載ollama部署 docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama### 下載模型 docker exec -it ollama ollama pull llama3### 交互式運行模型docker exec -i…

ECharts 最小高度設置指南

下面提供一份關于ECharts中設置最小高度的專業而詳細的文檔。這份文檔將涵蓋不同圖表類型的最小高度設置方法&#xff0c;適合初學者學習和參考。 ECharts 最小高度設置指南 1. 通用屬性 對于大多數圖表類型&#xff0c;可以使用以下通用屬性來控制最小高度&#xff1a; 1.…

算法 —— 二分查找

目錄 二分查找 在排序數組中查找元素的第一個和最后一個位置 搜索插入位置 x的平方根 山峰數組的峰頂索引 尋找峰值 搜索旋轉排序數組中的最?值 點名 二分查找模板分為三種&#xff1a;1、樸素的二分模板 2、查找左邊界的二分模板 3、查找右邊界的二分模板&#xf…

【基于R語言群體遺傳學】-12-超顯性與次顯性

歡迎先看前面的博客&#xff0c;再繼續進行后面的內容&#xff1a; 群體遺傳學_tRNA做科研的博客-CSDN博客 當雜合子的適應度超出純合子的范圍時&#xff0c;二倍體能夠展現出更多令人著迷的選擇實例。這種形式的一種是雜合子優勢&#xff0c;或稱為“超顯性”&#xff0c;其…