Add a CloseAction that will be executed each time the resource is closed.
Add a CloseAction that will be executed each time the resource is closed.
the action to add
a new resource instance with the close action added
Get the Resource context associated with this Resource instance.
Get the Resource context associated with this Resource instance.
the associated ResourceContext
as Resources are immutable objects a given Resource instance will always be associated with the same ResourceContext
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 }
the actual resource that has been opened
normally the error handler registered with the associated ResourceContext will handle any errors opening the resource, but when calling this method the caller must handle any possible errors that are raised.
Obtain the scalax.io.OutputResource(typically) version of this object.
Obtain the scalax.io.OutputResource(typically) version of this object.
the scalax.io.OutputResource(typically) version of this object.
Create a Resource instance that is configured with the new ResourceContext
Create a Resource instance that is configured with the new ResourceContext
A new ResourceContext
a new instance configured with the new context
Obtain the scalax.io.managed.WritableByteChannelResource(typically) version of this object.
Obtain the scalax.io.managed.WritableByteChannelResource(typically) version of this object.
the scalax.io.managed.WritableByteChannelResource(typically) version of this object.
Obtain the scalax.io.WriteCharsResource version of this object.
Obtain the scalax.io.WriteCharsResource version of this object.
the codec used to convert from bytes to characters
the scalax.io.WriteCharsResource version of this object.
Open the resource execute the function and either return all errors as a list or the result of the function execution.
Open the resource execute the function and either return all errors as a list or the result of the function execution.
On open and close error handlers in ResourceContext are called. If they then raise errors the errors are captured and returned as a Right[List[Throwable]]
Perhaps the worst method I have ever written :-(
If possible efficiently copy data from input.
If possible efficiently copy data from input. It MUST NOT forward request to input's copyTo method because that could trigger an infinate loop
Execute the function 'f' passing an Output instance that performs all operations on a single opened connection to the underlying resource.
Execute the function 'f' passing an Output instance that performs all operations on a single opened connection to the underlying resource. Typically each call to one of the Output's methods results in a new connection. For example if the underlying OutputStream truncates the file each time the connection is made then calling write two times will result in the contents of the second write overwriting the second write.
Even if the underlying resource is an appending, using open will be more efficient since the connection only needs to be made a single time.
the result of the function
Update the current ResourceContext and return a new Resource instance with the updated context
Update the current ResourceContext and return a new Resource instance with the updated context
A function for transforming the current context to a new context with new values.
a new instance configured with the new context
Writes a string.
Writes a string.
the data to write
the codec of the string to be written. The string will
be converted to the encoding of sourceCodec
Default is sourceCodec
Write data to the underlying object.
Write data to the underlying object. Each time write is called the resource is reopened, in the case of a file this means that the file will be opened and truncated. The
In the case of writing ints and bytes it is often recommended to write arrays of data since normally the underlying object can write arrays of bytes or integers most efficiently.
Since Characters require a codec to write to an OutputStream characters cannot be written with this method unless a OutputWriterFunction.CharFunction object is provided as the writer.
The data to write to underlying object. Any data that has a resolvable scalax.io.OutputConverter can be written. See the scalax.io.OutputConverter object for the defined scalax.io.OutputConverter implementations and classes to assist implementing more.
The strategy used to write the data to the underlying object. Many standard data-types are implicitly resolved and do not need to be supplied
#writeChars for more on writing characters
Since the scalax.io.OutputConverter object defined for writing Ints encodes Ints using 4 bytes this method is provided to simply write an array of Ints as if they are Bytes.
Since the scalax.io.OutputConverter object defined for writing Ints encodes Ints using 4 bytes this method is provided to simply write an array of Ints as if they are Bytes. In other words just taking the first byte. This is pretty common in Java.io style IO. IE
outputStream.write(1)
1 is written as a single byte.
Write several strings.
Write several strings.
The data to write
A string to add between each string. It is not added to the before the first string or after the last.
The codec of the strings to be written. The strings will
be converted to the encoding of sourceCodec
An Resource object that is a also an scalax.io.Output. This trait adds methods for converting between common io types such as to a scalax.io.managed.WriterResource or scalax.io.managed.WritableByteChannelResource
the type of underlying resource that is created
1.0