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
Obtain the scalax.io.managed.InputStreamResource(typically) version of this object.
Obtain the scalax.io.managed.InputStreamResource(typically) version of this object.
the scalax.io.managed.InputStreamResource(typically) version of this object.
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.
Obtain the scalax.io.managed.ReadableByteChannelResource(typically) version of this object.
Obtain the scalax.io.managed.ReadableByteChannelResource(typically) version of this object.
the scalax.io.managed.ReadableByteChannelResource(typically) version of this object.
Obtain the scalax.io.ReadCharsResource version of this object.
Obtain the scalax.io.ReadCharsResource version of this object.
the codec used to convert from bytes to characters
the scalax.io.ReadCharsResource version of this object.
Safely calculation the size of the resource or return None in case of failure or if it is not possible to determin size of resource before accessing the resource.
Safely calculation the size of the resource or return None in case of failure or if it is not possible to determin size of resource before accessing the resource.
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 :-(
Append a string to the end of the Seekable object.
Append a string to the end of the Seekable object.
the data to write
the codec of the string to be written. The string will be converted to the encoding of scalax.io.Codec
Append bytes to the end of a file
Append bytes to the end of a file
Important: The use of an Array is highly recommended because normally arrays can be more efficiently written using the underlying APIs
The data to write. This can be any type that has a scalax.io.OutputConverter associated with it. There are predefined $outputConverters for several types. See the scalax.io.OutputConverter object for the predefined types and for objects to simplify implementing custom scalax.io.OutputConverter
$converterParam
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.
Append several strings to the end of the Seekable object.
Append several strings to the end of the Seekable object.
The strings 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 scalax.io.Codec
Read the input as blocks of bytes.
Read the input as blocks of bytes. This method should be avoided unless the maximum performance is absolutely required because bytes provides very good performance and is a better API for most applications.
However since it better reflects how data is read with most input sources (like InputStreams and ReadableByteChannels); blocks is slightly more performance than bytes and therefore can be used when performance is the most important consideration.
block size can optionally be specified but the default is normally acceptable.
This method aspires to be the fastest way to read a stream of known length into memory.
This method aspires to be the fastest way to read a stream of known length into memory.
Obtains a Traversable for conveniently processing the resource as bytes.
Obtains a Traversable for conveniently processing the file as Ints.
The characters in the object.
The characters in the object.
If the codec is not the same as the source codec (the codec of the underlying data) then the characters will converted to the desired codec.
The codec representing the desired encoding of the characters
an traversable of all the characters
Copy all data from this Input object to the Output object as efficiently as possible.
Copy all data from this Input object to the Output object as efficiently as possible.
output sink to copy the data to
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
Inserts data at a position in the Seekable.
Inserts data at a position in the Seekable. The actual position in the Seekable where the data is inserted depends on the type of data being written. For example if Longs are being written then position calculated as position * 8
Important: The use of an Array is highly recommended because normally arrays can be more efficiently written using the underlying APIs
The position where the data is inserted into the Seekable. The actual position in the Seekable where the data is inserted depends on the type of data being written. For example if Longs are being written then position calculated as position * 8
The data to write. This can be any type that has a scalax.io.OutputConverter associated with it. There are predefined $outputConverters for several types. See the scalax.io.OutputConverter object for the predefined types and for objects to simplify implementing custom scalax.io.OutputConverter
$converterParam
Inserts a string at a position in the Seekable.
Inserts a string at a position in the Seekable. This is a potentially inefficient because of the need to count characters. If the codec is not a fixed sized codec (for example UTF8) each character must be converted in the file up to the point of insertion.
The position in the file to perform the insert. A position of 2 will insert the character after the second character (not byte).
The string that will be inserted into the Seekable
The codec to use for determining the location for inserting the string and for encoding the string as 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.
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.
Obtain an non-strict traversable for iterating through the lines in the object
Obtain an non-strict traversable for iterating through the lines in the object
If the codec is not the same as the source codec (the codec of the underlying data) then the characters will converted to the desired codec.
The strategy for determining the end of line Default is to auto-detect the EOL
if true then the line will end with the line terminator Default is false
The codec representing the desired encoding of the characters
a non-strict traversable for iterating through all the lines
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 a portion of the file content at the declared location.
Update a portion of the file content at the declared location. This is the most flexible of the random access methods but is also (probably) the trickiest to fully understand. That said it behaves (almost) identical to a scala.collection.Seq.patch method, so if you understand that you should not have difficulty understanding this method.
Important: The use of an Array is highly recommended because normally arrays can be more efficiently written using the underlying APIs
To append data the position must >= size
If the position is within the file but the
position + bytes.length
is beyond the end of the file the file will be enlarged so
that the entire string can fit in the file
The write begins at the position indicated. So if position = 0 then the write will begin at the first byte of the file.
The start position of the update starting at 0. The position must be within the file or == size (for appending)
The data to write. This can be any type that has a scalax.io.OutputConverter associated with it. There are predefined $outputConverters for several types. See the scalax.io.OutputConverter object for the predefined types and for objects to simplify implementing custom scalax.io.OutputConverter
The strategy that dictates how many characters/bytes/units are overwritten $converterParam
Update a portion of the file content at the declared location.
Update a portion of the file content at the declared location. This is the most flexible of the random access methods but is also (probably) the trickiest to fully understand. That said it behaves (almost) identical to a scala.collection.Seq.patch method, so if you understand that you should not have difficulty understanding this method.
If the position is beyond the end of the file a BufferUnderflow Exception will be thrown
If the position is within the file but the
position + string.getBytes(codec).length
is beyond the end of the file the file will be enlarged so
that the entire string can fit in the file
The write begins at the position indicated. So if position = 0 then the write will begin at the first byte of the file.
The start position of the update starting at 0. The position is the position'th character in the file using the codec for decoding the file The position must be within the file.
The string to write to the file starting at position.
The strategy that dictates how many characters/bytes/units are overwritten
The codec to use for decoding the underlying data into 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.
The number of bytes that can be read from the underlying resource.
The number of bytes that can be read from the underlying resource.
if length == None then it is not possible to determine the number of bytes in advance.
Loads all the characters into memory.
Loads all the characters into memory. There is no protection against loading very large files/amounts of data.
The codec representing the desired encoding of the characters
Create a temporary file to use for performing certain operations.
Create a temporary file to use for performing certain operations. It should be as efficient as possible to copy from the temporary file to this Seekable and vice-versa. Can be overridden for performance
Open a seekableByteChannelResource to use for creating other long traversables like chars or bytes as its.
Open a seekableByteChannelResource to use for creating other long traversables like chars or bytes as its.
This method may throw an exception if the file does not exist
Main feature is it sets position to 0 each call so the resource will always read from 0
Truncate/Chop the Seekable to the number of bytes declared by the position param
Truncate/Chop the Seekable to the number of bytes declared by the position param
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 object that can be viewed as a Seekable object. For example a FileChannel.
the type of the underlying Resource
1.0