类 ModuleResource

java.lang.Object
cn.taketoday.core.io.AbstractResource
cn.taketoday.core.io.ModuleResource
所有已实现的接口:
InputStreamSource, Resource, ThrowingConsumer<OutputStream>, Consumer<OutputStream>

public class ModuleResource extends AbstractResource
Resource implementation for Module resolution, performing getInputStream() access via Module.getResourceAsStream(java.lang.String).

Alternatively, consider accessing resources in a module path layout via ClassPathResource for exported resources, or specifically relative to a Class via ClassPathResource(String, Class) for local resolution within the containing module of that specific class. In common scenarios, module resources will simply be transparently visible as classpath resources and therefore do not need any special treatment at all.

从以下版本开始:
4.0
作者:
Juergen Hoeller, Sam Brannen, Harry Yang
另请参阅:
  • 字段详细资料

    • module

      private final Module module
    • path

      private final String path
  • 构造器详细资料

    • ModuleResource

      public ModuleResource(Module module, String path)
      Create a new ModuleResource for the given Module and the given resource path.
      参数:
      module - the runtime module to search within
      path - the resource path within the module
  • 方法详细资料

    • getModule

      public final Module getModule()
      Return the Module for this resource.
    • getPath

      public final String getPath()
      Return the path for this resource.
    • getInputStream

      public InputStream getInputStream() throws IOException
      从接口复制的说明: InputStreamSource
      Return an InputStream for the content of an underlying resource.

      It is expected that each call creates a fresh stream.

      This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each getInputStream() call returns a fresh stream.

      返回:
      the input stream for the underlying resource (must not be null)
      抛出:
      FileNotFoundException - if the underlying resource does not exist
      IOException - if the content stream could not be opened
      另请参阅:
    • createRelative

      public Resource createRelative(String relativePath)
      从接口复制的说明: Resource
      Create a resource relative to this resource.
      指定者:
      createRelative 在接口中 Resource
      覆盖:
      createRelative 在类中 AbstractResource
      参数:
      relativePath - the relative path (relative to this resource)
      返回:
      the resource handle for the relative resource
    • getName

      @Nullable public String getName()
      从类复制的说明: AbstractResource
      Determine the filename for this resource — typically the last part of the path — for example, "myfile.txt".

      Returns null if this type of resource does not have a filename.

      Implementations are encouraged to return the filename unencoded.

      指定者:
      getName 在接口中 Resource
      覆盖:
      getName 在类中 AbstractResource
    • toString

      public String toString()
      从接口复制的说明: Resource
      Return a description for this resource, to be used for error output when working with the resource.

      Implementations are also encouraged to return this value from their toString method.

      指定者:
      toString 在接口中 Resource
      覆盖:
      toString 在类中 AbstractResource
      另请参阅:
    • equals

      public boolean equals(@Nullable Object obj)
      覆盖:
      equals 在类中 AbstractResource
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 AbstractResource