主頁 > 後端開發 > Java基礎之SPI機制

Java基礎之SPI機制

2021-09-07 06:40:17 後端開發

SPI 機制,全稱為 Service Provider Interface,是一種服務發現機制,它通過在 ClassPath 路徑下的 META-INF/services 檔案夾查找檔案,自動加載檔案里所定義的類,這一機制為很多框架擴展提供了可能,比如在 Dubbo、JDBC 中都使用到了 SPI 機制,本文介紹了 Java SPI 機制以及在模塊化和非模塊話專案中的實作方式(此處的模塊化指 Java9 引入的模塊化)

SPI 機制介紹

SPI 全稱 Service Provider Interface,是 Java 提供的一套用來被第三方實作或者擴展的介面,它可以用來啟用框架擴展和替換組件, SPI 的作用就是為這些被擴展的 API 尋找服務實作,

SPI 和 API 的區別

API (Application Programming Interface)在大多數情況下,都是實作方制定介面并完成對介面的實作,呼叫方僅僅依賴介面呼叫,且無權選擇不同實作, 從使用人員上來說,API 直接被應用開發人員使用,如下圖所示,其中模塊 A 為介面制定方和實作方,而模塊 B 為介面的使用放,

API概念

維基百科關于 API 的描述:In building applications, an API (application programming interface) simplifies programming by abstracting the underlying implementation and only exposing objects or actions the developer needs. While a graphical interface for an email client might provide a user with a button that performs all the steps for fetching and highlighting new emails, an API for file input/output might give the developer a function that copies a file from one location to another without requiring that the developer understand the file system operations occurring behind the scenes.

SPI (Service Provider Interface)是呼叫方來制定介面規范,提供給外部來實作,呼叫方在呼叫時則選擇自己需要的外部實作,可用于啟用框架擴展和可替換組件, 從使用人員上來說,SPI 被框架擴展人員使用,如下圖所示,A 模塊是介面的定義方和使用方,而 B 模塊則是介面實作方,

SPI概念

SPI 維基百科定義:Service Provider Interface (SPI) is an API intended to be implemented or extended by a third party. It can be used to enable framework extension and replaceable components

SPI java 官方定義:A service is a well-known set of interfaces and (usually abstract) classes. A service provider(SPI) is a specific implementation of a service. The classes in a provider typically implement the interfaces and subclass the classes defined in the service itself. Service providers can be installed in an implementation of the Java platform in the form of extensions, that is, jar files placed into any of the usual extension directories. Providers can also be made available by adding them to the application's class path or by some other platform-specific means.

SPI 的優點

使用 Java SPI 機制的優勢是實作解耦,使得介面的定義與具體業務實作分離,而不是耦合在一起,應用行程可以根據實際業務情況啟用或替換具體組件,以 java 中的 JDBC 資料庫驅動為例,java 官方在核心庫制定了 java.sql.Driver 資料庫驅動介面,使用該介面實作了資料庫鏈接等邏輯,但是并沒有具體實作資料庫驅動介面,而是交給 MySql 等廠商去實作具體的資料庫介面,

參考自博客:Java SPI 主要是應用于廠商自定義組件或插件中,在 java.util.ServiceLoader 的檔案里有比較詳細的介紹,簡單的總結下 java SPI 機制的思想:我們系統里抽象的各個模塊,往往有很多不同的實作方案,比如日志模塊、xml 決議模塊、jdbc 模塊等方案,面向的物件的設計里,我們一般推薦模塊之間基于介面編程,模塊之間不對實作類進行硬編碼,一旦代碼里涉及具體的實作類,就違反了可拔插的原則,如果需要替換一種實作,就需要修改代碼,為了實作在模塊裝配的時候能不在程式里動態指明,這就需要一種服務發現機制, Java SPI 就是提供這樣的一個機制:為某個介面尋找服務實作的機制,有點類似 IOC 的思想,就是將裝配的控制權移到程式之外,在模塊化設計中這個機制尤其重要,

SPI 的約定

服務提供方需要通過一些約定告訴系統自己所提供的服務的位置,java9 之后一共有兩種約定方式:

  1. 通過在 META-INF/services/ 目錄下配置相關檔案實作,
  2. 通過 java9 jigsaw 的匯出陳述句指定服務位置,

    A service provider is a single type, usually a concrete class. An interface or abstract class is permitted because it may declare a static provider method, discussed later. The type must be public and must not be an inner class.
    A service provider and its supporting code may be developed in a module, which is then deployed on the application module path or in a modular image. Alternatively, a service provider and its supporting code may be packaged as a JAR file and deployed on the application class path. The advantage of developing a service provider in a module is that the provider can be fully encapsulated to hide all details of its implementation.
    An application that obtains a service loader for a given service is indifferent to whether providers of the service are deployed in modules or packaged as JAR files. The application instantiates service providers via the service loader's iterator, or via Provider objects in the service loader's stream, without knowledge of the service providers' locations.

模塊化陳述句約定

模塊化陳述句約定適用于專案已經模塊化的情況,以 java.sql.Driver 為例,在模塊化檔案 module-info.java 中添加如下陳述句,就可以向應用提供指定的服務:

provides java.sql.Driver with com.wangzemin.learning.provider.TestDriverProvider;

下文以一個自定義的 java.sql.Driver 服務提供者(也可以自己隨意再另外一個模塊定義一個介面)為例,展示 SPI 在 java 模塊化情況下約定的使用方式,

1. 示例專案目錄結構:
本文提供了一個完整的例子用于測驗主要包含三個檔案,TestDriverProvider(自定義的 Driver 服務提供者),module-info.java(java 模塊化檔案),Main(用于除錯以及輸出結果)

SPI模塊化目錄示例

2. 示例檔案內容
TestDriverProvider.java

public class TestDriverProvider implements Driver {
    // Override 的方法都為空,
}

模塊化檔案 module-info.java:

module provider {
    uses java.sql.Driver;
    requires java.sql;
    // 指定自定義的TestDriverProvider為Driver服務的提供者
    provides java.sql.Driver with com.wangzemin.learning.provider.TestDriverProvider;
}

主函式(ServiceLoader 用于查找合適的服務提供者,下文會詳細介紹):

public class Main {
    public static void main(String[] args) {
        ServiceLoader<Driver> loader = ServiceLoader.load(Driver.class);
        for (Driver item : loader) {
            System.out.println("Get class:" + item.getClass().descriptorString());
        }
    }
}

3. 示例的輸出

Get class:Lcom/wangzemin/learning/provider/TestDriverProvider;

由輸出可以看到,ServiceLoader 可以成功定位到 TestDriverProvider,

模塊化約定官方原文:
A service provider that is developed in a module must be specified in a provides directive in the module declaration. The provides directive specifies both the service and the service provider; this helps to locate the provider when another module, with a uses directive for the service, obtains a service loader for the service. It is strongly recommended that the module does not export the package containing the service provider. There is no support for a module specifying, in a provides directive, a service provider in another module.
A service provider that is developed in a module has no control over when it is instantiated, since that occurs at the behest of the application, but it does have control over how it is instantiated:
If the service provider declares a provider method, then the service loader invokes that method to obtain an instance of the service provider. A provider method is a public static method named "provider" with no formal parameters and a return type that is assignable to the service's interface or class.
In this case, the service provider itself need not be assignable to the service's interface or class.
If the service provider does not declare a provider method, then the service provider is instantiated directly, via its provider constructor. A provider constructor is a public constructor with no formal parameters.
In this case, the service provider must be assignable to the service's interface or class
A service provider that is deployed as an automatic module on the application module path must have a provider constructor. There is no support for a provider method in this case.
As an example, suppose a module specifies the following directives:

 provides com.example.CodecFactory with com.example.impl.StandardCodecs;
 provides com.example.CodecFactory with com.example.impl.ExtendedCodecsFactory;

where
com.example.CodecFactory is the two-method service from earlier.
com.example.impl.StandardCodecs is a public class that implements CodecFactory and has a public no-args constructor.
com.example.impl.ExtendedCodecsFactory is a public class that does not implement CodecFactory, but it declares a public static no-args method named "provider" with a return type of CodecFactory.
A service loader will instantiate StandardCodecs via its constructor, and will instantiate ExtendedCodecsFactory by invoking its provider method. The requirement that the provider constructor or provider method is public helps to document the intent that the class (that is, the service provider) will be instantiated by an entity (that is, a service loader) which is outside the class's package.

組態檔約定

組態檔約定適用于專案沒有模塊化的情況,需要在 classpath 下的 META-INF/services/ 目錄里創建一個以服務介面命名的檔案,這個檔案里的內容就是這個介面的具體的實作類,

下文同樣以一個自定義的 java.sql.Driver 服務提供者(也可以自己隨意再另外一個模塊定義一個介面)為例,展示 SPI 在 java 組態檔約定下的使用方式,

1. 示例專案目錄結構:
本文提供了一個完整的例子用于測驗主要包含三個檔案,TestDriverProvider(自定義的 Driver 服務提供者,和上文一致),Main(用于除錯以及輸出結果,和上文一致),META-INF/services/java.sql.Driver 檔案(用于指定服務提供著的位置)

2. 示例檔案內容
TestDriverProvider 和 Main 與上文中均一致,不再次詳述,此處僅僅展示 META-INF/services/java.sql.Driver 檔案的內容,該檔案只包含一行內容:

com.wangzemin.learning.learning.provider.TestDriverProvider

3. 示例的輸出

Get class:Lcom/wangzemin/learning/provider/TestDriverProvider;

由輸出可以看到,ServiceLoader 可以成功定位到 TestDriverProvider,

組態檔約定官方原文
A service provider that is packaged as a JAR file for the class path is identified by placing a provider-configuration file in the resource directory META-INF/services. The name of the provider-configuration file is the fully qualified binary name of the service. The provider-configuration file contains a list of fully qualified binary names of service providers, one per line.
For example, suppose the service provider com.example.impl.StandardCodecs is packaged in a JAR file for the class path. The JAR file will contain a provider-configuration file named:
META-INF/services/com.example.CodecFactory
that contains the line:
com.example.impl.StandardCodecs # Standard codecs
The provider-configuration file must be encoded in UTF-8. Space and tab characters surrounding each service provider's name, as well as blank lines, are ignored. The comment character is '#' ('\u0023' NUMBER SIGN); on each line all characters following the first comment character are ignored. If a service provider class name is listed more than once in a provider-configuration file then the duplicate is ignored. If a service provider class is named in more than one configuration file then the duplicate is ignored.
A service provider that is mentioned in a provider-configuration file may be located in the same JAR file as the provider-configuration file or in a different JAR file. The service provider must be visible from the class loader that is initially queried to locate the provider-configuration file; this is not necessarily the class loader which ultimately locates the provider-configuration file.

SPI 原理

上文講述了 SPI 的一些約定,那么有了這些約定之后,SPI 機制是如何定位到對應的服務提供者的類并進行加載的呢?SPI 服務的加載可以分為兩部分:

  1. 類全稱限定名的獲取,即知道哪些類是服務提供者,
  2. 類加載,把獲取到的類加載到記憶體中,涉及背景關系類加載器,

類限定名獲取

模塊化情況下

可以參考jigsaw 官方檔案,jigsaw 模塊化語法本身就支持 SPI 服務,通過 provide xxxx with yyyy,可以為 xxxx 服務指定一個服務提供者 yyyy,這個決議程序由 jigsaw 實作,

官方檔案說明:Services allow for loose coupling between service consumers modules and service providers modules.This example has a service consumer module and a service provider module:

  1. module com.socket exports an API for network sockets. The API is in package com.socket so this package is exported. The API is pluggable to allow for alternative implementations. The service type is class com.socket.spi.NetworkSocketProvider in the same module and thus package com.socket.spi is also exported.
  2. module org.fastsocket is a service provider module. It provides an implementation of com.socket.spi.NetworkSocketProvider. It does not export any packages.

配置的情況下

在指定配置的情況下,ServiceLoader.load 根據傳入的介面類,遍歷 META-INF/services 目錄下的以該類命名的檔案中的所有類,然再用類加載器加載這些服務,

SPI非模塊化目錄

類加載器加載

獲取到 SPI 服務實作類的檔案之后,就可以使用類加載器將對應的類加載到記憶體中, 問題在于,SPI 的介面是 Java 核心庫的一部分,是由引導類加載器來加載的;SPI 實作的 Java 類一般是由系統類加載器來加載的,引導類加載器是無法找到 SPI 的實作類的,因為它只加載 Java 的核心庫,它也不能代理給系統類加載器,因為它是系統類加載器的祖先類加載器,也就是說,類加載器的雙親委派模型無法解決這個問題,所以 java 采用了執行緒背景關系類加載器,破壞了“雙親委派模型”,可以在執行執行緒中拋棄雙親委派加載鏈模式,使程式可以逆向使用類加載器,從而實作 SPI 服務的加載,執行緒背景關系類加載器的實作如下:

  1. 在 ThreaLocal 中通過 setContextClassLoader?(ClassLoader cl)存盤當前執行緒中的類加載器,默認為 AppClassLoader,
  2. Java 核心庫中的程式在需要加載 SPI 實作類的時候,會首先通過 ThreaLocal 中的 getContextClassLoader?(ClassLoader cl)方法獲取背景關系類加載器,然后通過該類加載器加載 SPI 的實作類,

ServiceLoader

參考官方檔案,ServiceLoader 是用于加載 SPI 服務實作類的工具,可以處理 0 個、1 個或者多個服務提供商的情況,

官方說明:A facility to load implementations of a service.A service is a well-known interface or class for which zero, one, or many service providers exist. A service provider (or just provider) is a class that implements or subclasses the well-known interface or class. A ServiceLoader is an object that locates and loads service providers deployed in the run time environment at a time of an application’s choosing. Application code refers only to the service, not to service providers, and is assumed to be capable of differentiating between multiple service providers as well as handling the possibility that no service providers are located.

其主要方法為 public static ServiceLoader load?(Class service, ClassLoader loader),該方法根據需要加載的 SPI 介面和類加載器(默認情況為執行緒背景關系類加載器),生成一個 ServiceLoader,生成的 ServiceLoader 可以通過迭代器 Iterotor 或 stream 的方式獲取 SPI 的實作類,加載主要分為兩部分:模塊化的服務類加載和非模塊化的類加載,最后會對所有加載到的實作類排序,
注意:加載的服務類如果包含網路資源,可能會出現一些例外情況,

If the class path of the class loader includes remote network URLs then those URLs may be dereferenced in the process of searching for provider-configuration files.
This activity is normal, although it may cause puzzling entries to be created in web-server logs. If a web server is not configured correctly, however, then this activity may cause the provider-loading algorithm to fail spuriously.
A web server should return an HTTP 404 (Not Found) response when a requested resource does not exist. Sometimes, however, web servers are erroneously configured to return an HTTP 200 (OK) response along with a helpful HTML error page in such cases. This will cause a ServiceConfigurationError to be thrown when this class attempts to parse the HTML page as a provider-configuration file. The best solution to this problem is to fix the misconfigured web server to return the correct response code (HTTP 404) along with the HTML error page.

上文說到,SPI 可能有很多服務提供者,但是只有其中一些是有用的,這種情況下我們就需要對 ServiceLoader 獲取到的服務實作類進行過濾,比如,我們只需要 PNG 格式的 CodecFactory,那么我們就可以對對應的服務實作類添加一個自定義的@PNG 注解,然后通過下文過濾得到所需的服務提供者:

 ServiceLoader<CodecFactory> loader = ServiceLoader.load(CodecFactory.class);
 Set<CodecFactory> pngFactories = loader
        .stream()                                              // Note a below
        .filter(p -> p.type().isAnnotationPresent(PNG.class))  // Note b
        .map(Provider::get)                                    // Note c
        .collect(Collectors.toSet());

我是御狐神,歡迎大家關注我的微信公眾號

qrcode_for_gh_83670e17bbd7_344-2021-09-04-10-55-16

本文最先發布至微信公眾號,著作權所有,禁止轉載!

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/297990.html

標籤:其他

上一篇:某校教務管理系統post分析,Python實作自動查詢成績并發送短信

下一篇:劍指offer計劃6( 搜索與回溯演算法簡單版)---java

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【C++】Microsoft C++、C 和匯編程式檔案

    ......

    uj5u.com 2020-09-10 00:57:23 more
  • 例外宣告

    相比于斷言適用于排除邏輯上不可能存在的狀態,例外通常是用于邏輯上可能發生的錯誤。 例外宣告 Item 1:當函式不可能拋出例外或不能接受拋出例外時,使用noexcept 理由 如果不打算拋出例外的話,程式就會認為無法處理這種錯誤,并且應當盡早終止,如此可以有效地阻止例外的傳播與擴散。 示例 //不可 ......

    uj5u.com 2020-09-10 00:57:27 more
  • Codeforces 1400E Clear the Multiset(貪心 + 分治)

    鏈接:https://codeforces.com/problemset/problem/1400/E 來源:Codeforces 思路:給你一個陣列,現在你可以進行兩種操作,操作1:將一段沒有 0 的區間進行減一的操作,操作2:將 i 位置上的元素歸零。最終問:將這個陣列的全部元素歸零后操作的最少 ......

    uj5u.com 2020-09-10 00:57:30 more
  • UVA11610 【Reverse Prime】

    本人看到此題沒有翻譯,就附帶了一個自己的翻譯版本 思考 這一題,它的第一個要求是找出所有 $7$ 位反向質數及其質因數的個數。 我們應該需要質數篩篩選1~$10^{7}$的所有數,這里就不慢慢介紹了。但是,重讀題,我們突然發現反向質數都是 $7$ 位,而將它反過來后的數字卻是 $6$ 位數,這就說明 ......

    uj5u.com 2020-09-10 00:57:36 more
  • 統計區間素數數量

    1 #pragma GCC optimize(2) 2 #include <bits/stdc++.h> 3 using namespace std; 4 bool isprime[1000000010]; 5 vector<int> prime; 6 inline int getlist(int ......

    uj5u.com 2020-09-10 00:57:47 more
  • C/C++編程筆記:C++中的 const 變數詳解,教你正確認識const用法

    1、C中的const 1、區域const變數存放在堆疊區中,會分配記憶體(也就是說可以通過地址間接修改變數的值)。測驗代碼如下: 運行結果: 2、全域const變數存放在只讀資料段(不能通過地址修改,會發生寫入錯誤), 默認為外部聯編,可以給其他源檔案使用(需要用extern關鍵字修飾) 運行結果: ......

    uj5u.com 2020-09-10 00:58:04 more
  • 【C++犯錯記錄】VS2019 MFC添加資源不懂如何修改資源宏ID

    1. 首先在資源視圖中,添加資源 2. 點擊新添加的資源,復制自動生成的ID 3. 在解決方案資源管理器中找到Resource.h檔案,編輯,使用整個專案搜索和替換的方式快速替換 宏宣告 4. Ctrl+Shift+F 全域搜索,點擊查找全部,然后逐個替換 5. 為什么使用搜索替換而不使用屬性視窗直 ......

    uj5u.com 2020-09-10 00:59:11 more
  • 【C++犯錯記錄】VS2019 MFC不懂的批量添加資源

    1. 打開資源頭檔案Resource.h,在其中預先定義好宏 ID(不清楚其實ID值應該設定多少,可以先新建一個相同的資源項,再在這個資源的ID值的基礎上遞增即可) 2. 在資源視圖中選中專案資源,按F7編輯資源檔案,按 ID 型別 相對路徑的形式添加 資源。(別忘了先把檔案拷貝到專案中的res檔案 ......

    uj5u.com 2020-09-10 01:00:19 more
  • C/C++編程筆記:關于C++的參考型別,專供新手入門使用

    今天要講的是C++中我最喜歡的一個用法——參考,也叫別名。 參考就是給一個變數名取一個變數名,方便我們間接地使用這個變數。我們可以給一個變數創建N個參考,這N + 1個變數共享了同一塊記憶體區域。(參考型別的變數會占用記憶體空間,占用的記憶體空間的大小和指標型別的大小是相同的。雖然參考是一個物件的別名,但 ......

    uj5u.com 2020-09-10 01:00:22 more
  • 【C/C++編程筆記】從頭開始學習C ++:初學者完整指南

    眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......

    uj5u.com 2020-09-10 01:00:41 more
最新发布
  • Rust中的智能指標:Box<T> Rc<T> Arc<T> Cell<T> RefCell<T> Weak

    Rust中的智能指標是什么 智能指標(smart pointers)是一類資料結構,是擁有資料所有權和額外功能的指標。是指標的進一步發展 指標(pointer)是一個包含記憶體地址的變數的通用概念。這個地址參考,或 ” 指向”(points at)一些其 他資料 。參考以 & 符號為標志并借用了他們所 ......

    uj5u.com 2023-04-20 07:24:10 more
  • Java的值傳遞和參考傳遞

    值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......

    uj5u.com 2023-04-20 07:24:04 more
  • [2]SpinalHDL教程——Scala簡單入門

    第一個 Scala 程式 shell里面輸入 $ scala scala> 1 + 1 res0: Int = 2 scala> println("Hello World!") Hello World! 檔案形式 object HelloWorld { /* 這是我的第一個 Scala 程式 * 以 ......

    uj5u.com 2023-04-20 07:23:58 more
  • 理解函式指標和回呼函式

    理解 函式指標 指向函式的指標。比如: 理解函式指標的偽代碼 void (*p)(int type, char *data); // 定義一個函式指標p void func(int type, char *data); // 宣告一個函式func p = func; // 將指標p指向函式func ......

    uj5u.com 2023-04-20 07:23:52 more
  • Django筆記二十五之資料庫函式之日期函式

    本文首發于公眾號:Hunter后端 原文鏈接:Django筆記二十五之資料庫函式之日期函式 日期函式主要介紹兩個大類,Extract() 和 Trunc() Extract() 函式作用是提取日期,比如我們可以提取一個日期欄位的年份,月份,日等資料 Trunc() 的作用則是截取,比如 2022-0 ......

    uj5u.com 2023-04-20 07:23:45 more
  • 一天吃透JVM面試八股文

    什么是JVM? JVM,全稱Java Virtual Machine(Java虛擬機),是通過在實際的計算機上仿真模擬各種計算機功能來實作的。由一套位元組碼指令集、一組暫存器、一個堆疊、一個垃圾回收堆和一個存盤方法域等組成。JVM屏蔽了與作業系統平臺相關的資訊,使得Java程式只需要生成在Java虛擬機 ......

    uj5u.com 2023-04-20 07:23:31 more
  • 使用Java接入小程式訂閱訊息!

    更新完微信服務號的模板訊息之后,我又趕緊把微信小程式的訂閱訊息給實作了!之前我一直以為微信小程式也是要企業才能申請,沒想到小程式個人就能申請。 訊息推送平臺🔥推送下發【郵件】【短信】【微信服務號】【微信小程式】【企業微信】【釘釘】等訊息型別。 https://gitee.com/zhongfuch ......

    uj5u.com 2023-04-20 07:22:59 more
  • java -- 緩沖流、轉換流、序列化流

    緩沖流 緩沖流, 也叫高效流, 按照資料型別分類: 位元組緩沖流:BufferedInputStream,BufferedOutputStream 字符緩沖流:BufferedReader,BufferedWriter 緩沖流的基本原理,是在創建流物件時,會創建一個內置的默認大小的緩沖區陣列,通過緩沖 ......

    uj5u.com 2023-04-20 07:22:49 more
  • Java-SpringBoot-Range請求頭設定實作視頻分段傳輸

    老實說,人太懶了,現在基本都不喜歡寫筆記了,但是網上有關Range請求頭的文章都太水了 下面是抄的一段StackOverflow的代碼...自己大修改過的,寫的注釋挺全的,應該直接看得懂,就不解釋了 寫的不好...只是希望能給視頻網站開發的新手一點點幫助吧. 業務場景:視頻分段傳輸、視頻多段傳輸(理 ......

    uj5u.com 2023-04-20 07:22:42 more
  • Windows 10開發教程_編程入門自學教程_菜鳥教程-免費教程分享

    教程簡介 Windows 10開發入門教程 - 從簡單的步驟了解Windows 10開發,從基本到高級概念,包括簡介,UWP,第一個應用程式,商店,XAML控制元件,資料系結,XAML性能,自適應設計,自適應UI,自適應代碼,檔案管理,SQLite資料庫,應用程式到應用程式通信,應用程式本地化,應用程式 ......

    uj5u.com 2023-04-20 07:22:35 more