scalax.io

Resource

trait Resource [+R <: Closeable] extends ManagedResourceOperations[R] with ResourceOps[R, Resource[R]]

A Resource that can be used to do IO. Primarily it wraps objects from the java io and makes them more Scala friendly.

A common question about Resource is: "Why no simply expose Input, Output, Seekable, ReadChars, WriteChars? Why do we need a Resource[R] object?"

There are several reasons for this. There are several situations where a developer needs access to the underlying resource.

Perhaps they need to interact with a Java API which does not use the Input, etc... APIs. Another possibility is that the resource may be a specific implementation like PrintStream and they want to use those custom APIs instead of the Scala IO apis. In that case Resource provides them with the ARM functionality that is very useful.

R

The type of the resource that will be managed by the ManagedResource

Since

1.0

Linear Supertypes
ResourceOps[R, Resource[R]], ManagedResourceOperations[R], ManagedResource[R], AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. Resource
  2. ResourceOps
  3. ManagedResourceOperations
  4. ManagedResource
  5. AnyRef
  6. Any
Visibility
  1. Public
  2. All

Abstract Value Members

  1. def appendCloseAction [B >: R] (newAction: CloseAction[B]): Resource[R]

    Add a CloseAction to the end of the CloseAction queue (the last action executed).

    Add a CloseAction to the end of the CloseAction queue (the last action executed).

    newAction

    The new action to append

    returns

    a new instance with the added CloseAction

    Attributes
    abstract
    Definition Classes
    ResourceOps
  2. def open (): OpenedResource[R]

    Creates a new instance of the underlying resource (or opens it).

    Creates a new instance of the underlying resource (or opens it). Sometimes the code block used to create the Resource is non-reusable in which case this Resource can only be used once. This is not recommended. When creating a resource it is recommended to pass the code block for creating the resource to the resource so that the resource can be reused. Of course this is not always possible

    This method should only be used with care in cases when Automatic Resource Management cannot be used because the InputStream must be closed manually.

    This is public only to permit interoperability with certain Java APIs. A better pattern of use should be:

    resource.acquireFor {
      // call java API
    }
    

    or

    val calculatedResult = resource.acquireAndGet {
      // cal java API that returns a result
    }
    
    returns

    the actual resource that has been opened

    Attributes
    abstract
  3. def prependCloseAction [B >: R] (newAction: CloseAction[B]): Resource[R]

    Add a CloseAction to the front of the CloseAction queue.

    Add a CloseAction to the front of the CloseAction queue.

    newAction

    The new action to prepend

    returns

    a new instance with the added CloseAction

    Attributes
    abstract
    Definition Classes
    ResourceOps

Concrete Value Members

  1. def ! : R @scala.util.continuations.cpsParam[Unit,Unit]

    Definition Classes
    ManagedResourceOperations → ManagedResource
  2. def != (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  3. def != (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  4. def ## (): Int

    Attributes
    final
    Definition Classes
    AnyRef → Any
  5. def == (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  6. def == (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  7. def acquireAndGet [B] (f: (R) ⇒ B): B

    Definition Classes
    ManagedResourceOperations → ManagedResource
  8. def acquireFor [B] (f: (R) ⇒ B): Either[List[Throwable], B]

    Definition Classes
    Resource → ManagedResource
  9. def and [B] (that: ManagedResource[B]): ManagedResource[(R, B)]

    Definition Classes
    ManagedResourceOperations → ManagedResource
  10. def appendCloseAction [B >: R] (newAction: (B) ⇒ Unit): Resource[R]

    Creates a CloseAction from the function and passes it to appendCloseAction(CloseAction)

    Creates a CloseAction from the function and passes it to appendCloseAction(CloseAction)

    newAction

    The new action to append

    returns

    a new instance with the added CloseAction

    Definition Classes
    ResourceOps
  11. def asInstanceOf [T0] : T0

    Attributes
    final
    Definition Classes
    Any
  12. def clone (): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  13. def eq (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  14. def equals (arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  15. def finalize (): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  16. def flatMap [B, To] (f: (R) ⇒ B)(implicit translator: CanSafelyFlatMap[B, To]): To

    Definition Classes
    ManagedResourceOperations → ManagedResource
  17. def foreach (f: (R) ⇒ Unit): Unit

    Definition Classes
    ManagedResourceOperations → ManagedResource
  18. def getClass (): java.lang.Class[_]

    Attributes
    final
    Definition Classes
    AnyRef → Any
  19. def hashCode (): Int

    Definition Classes
    AnyRef → Any
  20. def isInstanceOf [T0] : Boolean

    Attributes
    final
    Definition Classes
    Any
  21. def map [B, To] (f: (R) ⇒ B)(implicit translator: CanSafelyMap[B, To]): To

    Definition Classes
    ManagedResourceOperations → ManagedResource
  22. def ne (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  23. def notify (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  24. def notifyAll (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  25. def prependCloseAction [B >: R] (newAction: (B) ⇒ Unit): Resource[R]

    Creates a CloseAction from the function and passes it to prependCloseAction(CloseAction)

    Creates a CloseAction from the function and passes it to prependCloseAction(CloseAction)

    newAction

    The new action to prepend

    returns

    a new instance with the added CloseAction

    Definition Classes
    ResourceOps
  26. def reflect [B] : R @util.continuations.package.cps[Either[List[Throwable],B]]

    Definition Classes
    ManagedResourceOperations → ManagedResource
  27. def synchronized [T0] (arg0: ⇒ T0): T0

    Attributes
    final
    Definition Classes
    AnyRef
  28. def toString (): String

    Definition Classes
    AnyRef → Any
  29. def toTraversable [B] (f: (R) ⇒ TraversableOnce[B]): Traversable[B]

    Definition Classes
    ManagedResourceOperations → ManagedResource
  30. def wait (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  31. def wait (arg0: Long, arg1: Int): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  32. def wait (arg0: Long): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from ResourceOps[R, Resource[R]]

Inherited from ManagedResourceOperations[R]

Inherited from ManagedResource[R]

Inherited from AnyRef

Inherited from Any