Resource

better.files.Resource$
See theResource companion trait
object Resource extends Resource

Implementations of Resource.

This object itself is a Resource uses the current thread's context class loader. It also creates Resources with different lookup behavior, using the methods at, from, and my. at searches rom a Class, from searches from a different ClassLoader, and my searches from the class, trait, or object surrounding the call.

Attributes

See also:
Companion:
trait
Graph
Supertypes
trait Resource
class Object
trait Matchable
class Any
Self type

Members list

Concise view

Value members

Concrete methods

def from(cl: ClassLoader): Resource

Look up resource files using the specified ClassLoader.

Look up resource files using the specified ClassLoader.

This Resource looks up resources from a specific ClassLoader. Like the default Resource, resource names are relative to the root package.

Attributes

cl

ClassLoader to look up resources from.

Returns:

A Resource that uses the supplied ClassLoader.

See also:
Example:
 Resource.from(appClassLoader).url("com/example/config.properties") 
def notFound(name: String): Nothing
override def url(name: String): Option[URL]

Look up a resource by name, and get its URL.

Look up a resource by name, and get its URL.

Attributes

name

Name of the resource to search for.

Returns:

URL of the requested resource. If the resource could not be found or is not accessible, returns None.

See also:
Definition Classes

Inherited methods

def asStream(name: String): Option[InputStream]

Look up a resource by name, and open an InputStream for reading it.

Look up a resource by name, and open an InputStream for reading it.

Attributes

name

Name of the resource to search for.

Returns:

InputStream for reading the found resource, if a resource was found.

See also:
Inherited from:
Resource
def asString(name: String, bufferSize: Int, charset: Charset): Option[String]

Attributes

Inherited from:
Resource
def at(clazz: Class[_]): Resource

Look up class resource files.

Look up class resource files.

This Resource looks up resources from the given Class, using Class#getResource. For example, if classOf[com.example.ExampleClass] is given for clazz, then resource files will be searched for in the com/example folder containing ExampleClass.class.

If you want to look up resource files relative to the call site instead (that is, you want your class to look up one of its own resources), use the my method instead.

Attributes

clazz

The class to look up from.

Returns:

A Resource for clazz.

See also:
Example:
Resource.at(Class.forName("your.AppClass")).url("config.properties")

In this example, a file named config.properties is expected to appear alongside the file AppClass.class in the package your.

Inherited from:
ResourceCompat (hidden)
inline def at[T]: Resource

Look up class resource files.

Look up class resource files.

This Resource looks up resources relative to the JVM class file for T, using Class#getResource. For example, if com.example.ExampleClass is given for T, then resource files will be searched for in the com/example folder containing ExampleClass.class.

If you want to look up resource files relative to the call site instead (that is, you want a class to look up one of its own resources), use the my method instead.

Attributes

T

The class, trait, or object to look up from. Objects must be written with a .type suffix, such as Resource.at[SomeObject.type].

Returns:

A Resource for T.

See also:
Example:
Resource.at[YourClass].url("config.properties")
Inherited from:
ResourceCompat (hidden)
def getAsStream(name: String): InputStream

Same as asStream but throws a NoSuchElementException if resource is not found

Same as asStream but throws a NoSuchElementException if resource is not found

Attributes

Inherited from:
Resource
def getAsString(name: String, bufferSize: Int, charset: Charset): String

Attributes

Inherited from:
Resource
def getUrl(name: String): URL

Get URL of given resource A default argument of empty string is provided to conveniently get the root resource URL using {{Resource.getUrl()}}

Get URL of given resource A default argument of empty string is provided to conveniently get the root resource URL using {{Resource.getUrl()}}

Attributes

Inherited from:
Resource
inline def my: Resource

Look up own resource files.

Look up own resource files.

This Resource looks up resources from the Class surrounding the call, using Class#getResource. For example, if my is called from com.example.ExampleClass, then resource files will be searched for in the com/example folder containing ExampleClass.class.

Attributes

Returns:

A Resource for the call site.

See also:
Example:
Resource.my.url("config.properties")
Inherited from:
ResourceCompat (hidden)