日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Introduction to the Service Provider Interfaces--官方文档

發布時間:2025/4/5 编程问答 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Introduction to the Service Provider Interfaces--官方文档 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

地址:https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html

What Are Services?

Services are units of sound-handling functionality that are automatically available when an application program makes use of an implementation of the Java Sound API. They consist of objects that do the work of reading, writing, mixing, processing, and converting audio and MIDI data. An implementation of the Java Sound API generally supplies a basic set of services, but mechanisms are also included in the API to support the development of new sound services by third-party developers (or by the vendor of the implementation itself). These new services can be "plugged into" an existing installed implementation to expand its functionality without requiring a new release. In the Java Sound API architecture, third-party services are integrated into the system in such a way that an application program's interface to them is the same as the interface to the "built-in" services. In some cases, application developers who use thejavax.sound.sampled?and?javax.sound.midi?packages might not even be aware that they are employing third-party services.

Examples of potential third-party, sampled-audio services include:

  • Sound file readers and writers
  • Converters that translate between different audio data formats
  • New audio mixers and input/output devices, whether implemented purely in software, or in hardware with a software interface

Third-party MIDI services might consist of:

  • MIDI file readers and writers
  • Readers for various types of soundbank files (which are often specific to particular synthesizers)
  • MIDI-controlled sound synthesizers, sequencers, and I/O ports, whether implemented purely in software, or in hardware with a software interface

How Services Work

The?javax.sound.sampled?and?javax.sound.midi?packages provide functionality to application developers who wish to include sound services in their application programs. These packages are for?consumers?of sound services, providing interfaces to get information about, control, and access audio and MIDI services. In addition, the Java Sound API also supplies two packages that define abstract classes to be used by?providers?of sound services: the?javax.sound.sampled.spi?and?javax.sound.midi.spi?packages.

Developers of new sound services implement concrete subclasses of the appropriate classes in the SPI packages. These subclasses, along with any additional classes required to support the new service, are placed in a Java Archive (JAR) archive file with a description of the included service or services. When this JAR file is installed in the user's?CLASSPATH, the runtime system automatically makes the new service available, extending the functionality of the Java platform's runtime system.

Once the new service is installed, it can be accessed just like any previously installed service. Consumers of services can get information about the new service, or obtain instances of the new service class itself, by invoking methods of the?AudioSystem?and?MidiSystem?classes (in the?javax.sound.sampled?and?javax.sound.midi?packages, respectively) to return information about the new services, or to return instances of new or existing service classes themselves. Application programs need not—and should not—reference the classes in the SPI packages (and their subclasses) directly to make use of the installed services.

For example, suppose a hypothetical service provider called Acme Software, Inc. is interested in supplying a package that allows application programs to read a new format of sound file (but one whose audio data is in a standard data format). The SPI class?AudioFileReader?can be subclassed into a class called, say,?AcmeAudioFileReader. In the new subclass, Acme would supply implementations of all the methods defined in?AudioFileReader; in this case there are only two methods (with argument variants),?getAudioFileFormat?andgetAudioInputStream. Then when an application program attempted to read a sound file that happened to be in Acme's file format, it would invoke methods of the?AudioSystem?class injavax.sound.sampled?to access the file and information about it. The methods?AudioSystem.getAudioInputStream?and?AudioSystem.getAudioFileFormat?provide a standard API to read audio streams; with the?AcmeAudioFileReader?class installed, this interface is extended to support the new file type transparently. Application developers don't need direct access to the newly registered SPI classes: the?AudioSystem?object methods pass the query on to the installed?AcmeAudioFileReader?class.

What's the point of having these "factory" classes? Why not permit the application developer to get access directly to newly provided services? That is a possible approach, but having all management and instantiation of services pass through gatekeeper system objects shields the application developer from having to know anything about the identity of installed services. Application developers just use services of value to them, perhaps without even realizing it. At the same time this architecture permits service providers to effectively manage the available resources in their packages.

Often the use of new sound services is transparent to the application program. For example, imagine a situation where an application developer wants to read in a stream of audio from a file. Assuming that?thePathName?identifies an audio input file, the program does this:

File theInFile = new File(thePathName);AudioInputStream theInStream = AudioSystem.getAudioInputStream(theInFile);

Behind the scenes, the?AudioSystem?determines what installed service can read the file and asks it to supply the audio data as an?AudioInputStream?object. The developer might not know or even care that the input audio file is in some new file format (such as Acme's), supported by installed third-party services. The program's first contact with the stream is through theAudioSystem?object, and all its subsequent access to the stream and its properties are through the methods of?AudioInputStream. Both of these are standard objects in thejavax.sound.sampled?API; the special handling that the new file format may require is completely hidden.

How Providers Prepare New Services

Service providers supply their new services in specially formatted JAR files, which are to be installed in a directory on the user's system where the Java runtime will find them. JAR files are archive files, each containing sets of files that might be organized in hierarchical directory structures within the archive. Details about the preparation of the class files that go into these archives are discussed in the next few pages, which describe the specifics of the audio and MIDI SPI packages; here we'll just give an overview of the process of JAR file creation.

The JAR file for a new service or services should contain a class file for each service supported in the JAR file. Following the Java platform's convention, each class file has the name of the newly defined class, which is a concrete subclass of one of the abstract service provider classes. The JAR file also must include any supporting classes required by the new service implementation. So that the new service or services can be located by the runtime system's service provider mechanism, the JAR file must also contain special files (described below) that map the SPI class names to the new subclasses being defined.

To continue from our example above, say Acme Software, Inc. is distributing a package of new sampled-audio services. Let's suppose this package consists of two new services:

  • The?AcmeAudioFileReader?class, which was mentioned above, and which is a subclass of?AudioFileReader
  • A subclass of?AudioFileWriter?called?AcmeAudioFileWriter, which will write sound files in Acme's new format

Starting from an arbitrary directory—let's call it?/devel—where we want to do the build, we create subdirectories and put the new class files in them, organized in such a manner as to give the desired pathname by which the new classes will be referenced:

com/acme/AcmeAudioFileReader.classcom/acme/AcmeAudioFileWriter.class

In addition, for each new SPI class being subclassed, we create a mapping file in a specially named directory?META-INF/services. The name of the file is the name of the SPI class being subclassed, and the file contains the names of the new subclasses of that SPI abstract class.

We create the file

META-INF/services/javax.sound.sampled.spi.AudioFileReader

which consists of

# Providers of sound file-reading services # (a comment line begins with a pound sign)com.acme.AcmeAudioFileReader

and also the file

META-INF/services/javax.sound.sampled.spi.AudioFileWriter

which consists of

# Providers of sound file-writing services com.acme.AcmeAudioFileWriter

Now we run?jar?from any directory with the command line:

jar cvf acme.jar -C /devel .

The?-C?option causes?jar?to switch to the?/devel?directory, instead of using the directory in which the command is executed. The final period argument instructs?jar?to archive all the contents of that directory (namely,?/devel), but not the directory itself.

This run will create the file?acme.jar?with the contents:

com/acme/AcmeAudioFileReader.class com/acme/AcmeAudioFileWriter.class META-INF/services/javax.sound.sampled.spi.AudioFileReader META-INF/services/javax.sound.sampled.spi.AudioFileWriter META-INF/Manifest.mf

The file?Manifest.mf,?which is generated by the?jar?utility itself, is a list of all the files contained in the archive.

How Users Install New Services

For end users (or system administrators) who wish to get access to a new service through their application programs, installation is simple. They place the provided JAR file in a directory in theirCLASSPATH.?Upon execution, the Java runtime will find the referenced classes when needed.

It's not an error to install more than one provider for the same service. For example, two different service providers might supply support for reading the same type of sound file. In such a case, the system arbitrarily chooses one of the providers. Users who care which provider is chosen should install only the desired one.

轉載于:https://www.cnblogs.com/davidwang456/p/5895840.html

總結

以上是生活随笔為你收集整理的Introduction to the Service Provider Interfaces--官方文档的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产精品综合久久久久久 | 丝袜美腿一区二区三区 | 美女无遮挡网站 | 污视频网站入口 | 国产免费一区二区三区 | 91免费看. | 日韩美女视频网站 | 免费看a视频 | 操干视频 | 解开人妻的裙子猛烈进入 | 免费看国产曰批40分钟 | 黄色一级在线视频 | 麻豆导航 | 亚洲h| 性色AV无码久久一区二区三 | 疯狂做爰的爽文多肉小说王爷 | aaa国产精品| 熟女少妇a性色生活片毛片 亚洲伊人成人网 | 天天综合网国产 | 丝袜美腿一区二区三区 | 色婷婷www | 欧美日本在线视频 | 欧美大片一级 | 东北熟女一区二区三区 | 天天爽夜夜爽一区二区三区 | 日日碰狠狠添天天爽无码av | 亚州激情视频 | 无码精品视频一区二区三区 | 美女脱了裤子让男人桶 | 欧美日韩大片在线观看 | 国产区一二| 自拍色图 | 日韩av毛片 | av噜噜噜 | 国产1区2区3区中文字幕 | 天堂一区二区三区 | 色黄啪啪网 | 国产a级免费视频 | 九色.com| 91亚洲精选 | 国产成人在线影院 | 亚洲精品在线免费播放 | 久久久久久久久久久网站 | 波多野吉衣伦理片 | av丁香| 最近更新中文字幕 | 麻豆视频在线观看免费 | 亚洲人成在线观看 | 亚洲一线二线在线观看 | 丝袜五月天 | 中文字幕在线永久 | 一区视频 | 亚洲一区二区三区四区五区六区 | 美女福利片 | 久在线播放 | 欧美成人精品欧美一级私黄 | 女性私密整形视频 | 国产无限资源 | 活大器粗np高h一女多夫 | www.日本com| 国产第三区 | 亚洲成人黄色影院 | 四川丰满妇女毛片四川话 | 国产亚洲精品久久久久久久久动漫 | 91啪国产 | 日本成人精品 | 黄色福利网站 | 一区二区视频免费在线观看 | 小小姑娘电影大全免费播放 | 免费视频亚洲 | 色婷婷在线观看视频 | 国内精品久久久久 | 日日夜夜噜 | 97成网| 一级大片儿 | 在线观看免费黄视频 | 国产欧美一区二区三区四区 | 国产精品后入内射日本在线观看 | 伊人久久大香线蕉综合75 | 老头糟蹋新婚少妇系列小说 | 在线观看欧美一区二区三区 | 大胸美女被爆操 | 欧美在线一区二区 | 亚洲AV蜜桃永久无码精品性色 | 永久免费在线观看视频 | 朝桐光av一区二区三区 | 德国老妇性猛交 | 国产一级av毛片 | 丁香花电影免费播放在线观看 | 欧美 日韩 国产 一区二区三区 | 成人动作片 | 国产精品36p | 99久热| 日日噜噜噜夜夜爽爽狠狠 | 日本三级中文字幕在线观看 | 成人一二区 | 日本黄色大片网站 | 精品国产丝袜一区二区三区乱码 | 天天色一色 |