package util
Miscellaneous utility functions and methods not otherwise categorized.
- Alphabetic
- By Inheritance
- util
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
CanReleaseResource[-T] extends AnyRef
withResource()
needs an implicit evidence parameter of this type to know how to release what's passed to it.withResource()
needs an implicit evidence parameter of this type to know how to release what's passed to it.- T
the type (which must be contravariant to allow, for instance, a
T
ofCloseable
to apply to subclasses likeInputStream
).
- Annotations
- @implicitNotFound( ... )
Value Members
-
def
tryWithResource[T, R](open: ⇒ T)(code: (T) ⇒ R)(implicit mgr: CanReleaseResource[T]): Try[R]
A version of grizzled.util.withResource that captures any thrown exception, instead of propagating it.
A version of grizzled.util.withResource that captures any thrown exception, instead of propagating it.
- T
the type of the resource
- R
the return type of the code block
- open
the by-name parameter (code block) to open the resource. This parameter is a by-name parameter so that this function can capture any exceptions it throws.
- code
the code block to execute with the resource
- mgr
the resource manager that can release the resource
- returns
A
Success
containing the result of the code block, or aFailure
with any thrown exception.
-
def
withResource[T, R](resource: T)(code: (T) ⇒ R)(implicit mgr: CanReleaseResource[T]): R
Ensure that a closeable object is closed.
Ensure that a closeable object is closed. Note that this function requires an implicit evidence parameter of type
CanClose
to determine how to close the object. You can implement your own, though common ones are provided automatically.Sample use:
withResource(new java.io.FileInputStream("/path/to/file")) { in => ... }
Note: If the block throws an exception,
withResource
propagates the exception. If you want to capture the exception, instead, use grizzled.util.tryWithResource.- T
the type of the resource
- R
the return type of the code block
- resource
the object that holds a resource to be released
- code
the code block to execute with the resource
- mgr
the resource manager that can release the resource
- returns
whatever the block returns
-
object
CanReleaseResource
Companion object for
CanReleaseResource
. - object Implicits