Spring Configuration Resource Resource

Source: Internet
Author: User

In Java, resources from different sources are abstracted into URLs, and the read logic of resources from different sources is handled by registering different handler (URLStreamHandler). Generic handler types are identified using different prefixes (protocols, protocal), such as: "File:", "http:", "jar:", and so on. For spring,url not defined corresponding, such as "Classpath:" Handler, the definition is also relatively troublesome, spring to the configuration file read the corresponding encapsulation, through the resource interface to abstract the underlying resources. As follows:
/*** Interface for a resource descriptor this abstracts from the actual * type of underlying resource, such as a file or Class path resource.  * * <p>an InputStream can be opened for every resource if it exists in * physical form, but a URL or File handle can Just is returned for * certain resources. The actual behavior is implementation-specific. * * @authorJuergen Hoeller *@since28.12.2003 *@see#getInputStream () *@see#getURL () *@see#getURI () *@see#getFile () *@seeWritableresource *@seeContextresource *@seeFilesystemresource *@seeClasspathresource *@seeUrlresource *@seeBytearrayresource *@seeInputstreamresource *@seePathresource*/ Public InterfaceResourceextendsInputstreamsource {/*** Return Whether this resource actually exists in physical form. * <p>this method performs a definitive existence check, whereas the * existence of a {@codeResource} Handle only guarantees a * valid descriptor handle. */    Booleanexists (); /*** Return Whether the contents of this resource can be read, * e.g. via {@link#getInputStream ()} or {@link#getFile ()}. * <p>will be {@codetrue} for typical resource descriptors;     * Note that actual content reading could still fail when attempted. * However, a value of {@codefalse} is a definitive indication *, the resource content cannot be read. * @see#getInputStream ()*/    Booleanisreadable (); /*** Return Whether this resource represents a handle with an open * stream.     If true, the InputStream cannot be read multiple times, * and must is read and closed to avoid resource leaks. * <p>will be {@codefalse} for typical resource descriptors. */    BooleanIsOpen (); /*** Return A URL handle for this resource. * @throwsIOException If the resource cannot be resolved as URL, * i.e. if the resource are not available as descriptor */URL GetURL ()throwsIOException; /*** Return A URI handle for this resource. * @throwsIOException If the resource cannot be resolved as URI, * i.e. if the resource are not available as descriptor */URI GetURI ()throwsIOException; /*** Return A File handle for this resource. * @throwsIOException If the resource cannot be resolved as absolute * file path, i.e. if the resource was not available in A file system*/File getFile ()throwsIOException; /*** Determine the content length for this resource. * @throwsIOException If the resource cannot is resolved * (in the file system or as some other known physical resource Ty PE)*/    LongContentLength ()throwsIOException; /*** Determine the last-modified timestamp for this resource. * @throwsIOException If the resource cannot is resolved * (in the file system or as some other known physical resource Typ e)*/    LongLastModified ()throwsIOException; /*** Create A resource relative to this resource. * @paramRelativePath the relative path (relative to this resource) *@returnThe resource handle for the relative resource *@throwsIOException If the relative resource cannot be determined*/Resource createrelative (String relativepath)throwsIOException; /*** Determine a filename for this resource, i.e typically the last * part of the path:for example, "Myfile.tx     T ". * <p>returns {@codenull} If this type of resource does not * has a filename. */String GetFileName (); /*** Return A description for this resource, * to is used for error output when working with the resource. * <p>implementations is also encouraged to return the value * from their {@codeToString} method. * @seeobject#tostring ()*/String getdescription ();}

There are corresponding resource implementations for resource files from different sources, files (filesystemresource), classpath Resources (classpathresource), URL resources (urlresource), InputStream resource (Inputstreamresource), byte array resource (Bytearrayresource), and so on.

Spring Configuration Resource Resource

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.