scalax.io.managed

SeekableByteChannelResource

class SeekableByteChannelResource[+A <: SeekableByteChannel] extends SeekableResource[A] with ResourceOps[A, SeekableByteChannelResource[A]]

A ManagedResource for accessing and using SeekableByteChannels. Class can be created using the scalax.io.Resource object.

Self Type
SeekableByteChannelResource[A]
Linear Supertypes
SeekableResource[A], OutputResource[A], InputResource[A], Resource[A], ResourceOps[A, SeekableByteChannelResource[A]], ManagedResourceOperations[A], ManagedResource[A], Seekable, Output, Input, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. SeekableByteChannelResource
  2. SeekableResource
  3. OutputResource
  4. InputResource
  5. Resource
  6. ResourceOps
  7. ManagedResourceOperations
  8. ManagedResource
  9. Seekable
  10. Output
  11. Input
  12. AnyRef
  13. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new SeekableByteChannelResource(opener: (Seq[OpenOption]) ⇒ A, context: ResourceContext = DefaultResourceContext, closeAction: CloseAction[A] = CloseAction.Noop, sizeFunc: () ⇒ Option[Long] = () => None, openOptions: Option[Seq[OpenOption]] = None)

Value Members

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

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

    Definition Classes
    AnyRef → Any
  3. final def ##(): Int

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

    Definition Classes
    AnyRef → Any
  5. def acquireAndGet[B](f: (A) ⇒ B): B

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

    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 :-(

    Definition Classes
    Resource → ManagedResource
  7. def addCloseAction(newCloseAction: CloseAction[A]): SeekableByteChannelResource[A]

    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.

    newCloseAction

    the action to add

    returns

    a new resource instance with the close action added

    Definition Classes
    SeekableByteChannelResourceResourceOps
  8. def and[B](that: ManagedResource[B]): ManagedResource[(A, B)]

    Definition Classes
    ManagedResourceOperations → ManagedResource
  9. def append(string: String)(implicit codec: Codec = Codec.default): Unit

    Append a string to the end of the Seekable object.

    Append a string to the end of the Seekable object.

    string

    the data to write

    codec

    the codec of the string to be written. The string will be converted to the encoding of scalax.io.Codec

    Definition Classes
    Seekable
  10. def append[T](data: T)(implicit converter: OutputConverter[T]): Unit

    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

    data

    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

    Definition Classes
    Seekable
  11. def appendChannel[U](f: (SeekableByteChannel) ⇒ U): U

    Attributes
    protected
    Definition Classes
    Seekable
  12. def appendIntsAsBytes(data: Int*): Unit

    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.

    Definition Classes
    Seekable
  13. def appendStrings(strings: Traversable[String], separator: String = "")(implicit codec: Codec = Codec.default): Unit

    Append several strings to the end of the Seekable object.

    Append several strings to the end of the Seekable object.

    strings

    The strings to write

    separator

    A string to add between each string. It is not added to the before the first string or after the last.

    codec

    The codec of the strings to be written. The strings will be converted to the encoding of scalax.io.Codec

    Definition Classes
    Seekable
  14. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  15. def blocks(blockSize: Option[Int] = None): LongTraversable[ByteBlock]

    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.

    blockSize

    block size can optionally be specified but the default is normally acceptable.

    Definition Classes
    SeekableByteChannelResourceSeekableInput
  16. def byteArray: Array[Byte]

    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.

    Definition Classes
    Input
  17. def bytes: LongTraversable[Byte]

    Obtains a Traversable for conveniently processing the resource as bytes.

    Obtains a Traversable for conveniently processing the resource as bytes.

    returns

    an non-strict traversable over all the bytes

    Definition Classes
    SeekableByteChannelResourceSeekableInput
  18. def bytesAsInts: LongTraversable[Int]

    Obtains a Traversable for conveniently processing the file as Ints.

    Obtains a Traversable for conveniently processing the file as Ints.

    returns

    an non-strict traversable over all the bytes with the bytes being represented as Ints

    Definition Classes
    SeekableByteChannelResourceSeekableInput
  19. def chars(implicit codec: Codec): LongTraversable[Char]

    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.

    codec

    The codec representing the desired encoding of the characters

    returns

    an traversable of all the characters

    Definition Classes
    SeekableInput
  20. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. val context: ResourceContext

    Get the Resource context associated with this Resource instance.

    Get the Resource context associated with this Resource instance.

    returns

    the associated ResourceContext

    Definition Classes
    SeekableByteChannelResourceResourceOpsSeekableInput
    Note

    as Resources are immutable objects a given Resource instance will always be associated with the same ResourceContext

  22. def copyDataTo(output: Output): Unit

    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

    output sink to copy the data to

    Definition Classes
    InputResourceInput
  23. def doCopyFrom(input: Input): Unit

    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

    Definition Classes
    OutputResourceOutput
  24. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  25. def equals(arg0: Any): Boolean

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

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  27. def flatMap[B](f: (A) ⇒ ManagedResource[B]): ManagedResource[B]

    Definition Classes
    ManagedResourceOperations → ManagedResource
  28. def foreach(f: (A) ⇒ Unit): Unit

    Definition Classes
    ManagedResourceOperations → ManagedResource
  29. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  30. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  31. def inputStream: InputStreamResource[ChannelInputStreamAdapter[A]]

    Obtain the scalax.io.managed.InputStreamResource(typically) version of this object.

    Obtain the scalax.io.managed.InputStreamResource(typically) version of this object.

    returns

    the scalax.io.managed.InputStreamResource(typically) version of this object.

    Definition Classes
    SeekableByteChannelResourceInputResource
  32. def insert[T](position: Long, data: T)(implicit converter: OutputConverter[T]): Any

    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

    position

    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

    data

    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

    Definition Classes
    Seekable
  33. def insert(position: Long, string: String)(implicit codec: Codec = Codec.default): Unit

    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.

    position

    The position in the file to perform the insert. A position of 2 will insert the character after the second character (not byte).

    string

    The string that will be inserted into the Seekable

    codec

    The codec to use for determining the location for inserting the string and for encoding the string as bytes

    Definition Classes
    Seekable
  34. def insertIntsAsBytes(position: Long, data: Int*): Any

    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.

    Definition Classes
    Seekable
  35. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  36. def lines(terminator: Terminator = Terminators.Auto, includeTerminator: Boolean = false)(implicit codec: Codec = Codec.default): LongTraversable[String]

    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.

    terminator

    The strategy for determining the end of line Default is to auto-detect the EOL

    includeTerminator

    if true then the line will end with the line terminator Default is false

    codec

    The codec representing the desired encoding of the characters

    returns

    a non-strict traversable for iterating through all the lines

    Definition Classes
    Input
  37. def map[B](f: (A) ⇒ B): ExtractableManagedResource[B]

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

    Definition Classes
    AnyRef
  39. final def notify(): Unit

    Definition Classes
    AnyRef
  40. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  41. def now: A @scala.util.continuations.cpsParam[Unit,Unit]

    Definition Classes
    ManagedResourceOperations → ManagedResource
  42. def open(): OpenedResource[A]

    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

    Definition Classes
    SeekableByteChannelResourceResource
    Note

    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.

  43. val openOptions: Option[Seq[OpenOption]]

    Attributes
    protected
  44. def outputProcessor: OutputProcessor

    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.

    returns

    the result of the function

    Definition Classes
    Output
  45. def outputStream: OutputStreamResource[ChannelOutputStreamAdapter[A]]

    Obtain the scalax.io.OutputResource(typically) version of this object.

    Obtain the scalax.io.OutputResource(typically) version of this object.

    returns

    the scalax.io.OutputResource(typically) version of this object.

    Definition Classes
    SeekableByteChannelResourceOutputResource
  46. def patch[T](position: Long, data: T, overwrite: Overwrite)(implicit converter: OutputConverter[T]): Unit

    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.

    position

    The start position of the update starting at 0. The position must be within the file or == size (for appending)

    data

    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

    overwrite

    The strategy that dictates how many characters/bytes/units are overwritten $converterParam

    Definition Classes
    Seekable
  47. def patch(position: Long, string: String, overwrite: Overwrite)(implicit codec: Codec = Codec.default): Unit

    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.

    position

    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.

    string

    The string to write to the file starting at position.

    overwrite

    The strategy that dictates how many characters/bytes/units are overwritten

    codec

    The codec to use for decoding the underlying data into characters

    Definition Classes
    Seekable
  48. def patchIntsAsBytes(position: Long, overwrite: Overwrite, data: Int*): Unit

    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.

    Definition Classes
    Seekable
  49. def readWriteChannel[U](f: (SeekableByteChannel) ⇒ U): U

    Attributes
    protected
    Definition Classes
    Seekable
  50. def readableByteChannel: ReadableByteChannelResource[A]

    Obtain the scalax.io.managed.ReadableByteChannelResource(typically) version of this object.

    Obtain the scalax.io.managed.ReadableByteChannelResource(typically) version of this object.

    returns

    the scalax.io.managed.ReadableByteChannelResource(typically) version of this object.

    Definition Classes
    SeekableByteChannelResourceInputResource
  51. def reader(implicit sourceCodec: Codec): ReaderResource[ChannelReaderAdapter[A]]

    Obtain the scalax.io.ReadCharsResource version of this object.

    Obtain the scalax.io.ReadCharsResource version of this object.

    sourceCodec

    the codec used to convert from bytes to characters

    returns

    the scalax.io.ReadCharsResource version of this object.

    Definition Classes
    SeekableByteChannelResourceInputResource
  52. def reflect[B]: A @scala.util.continuations.cpsParam[Either[List[Throwable],B],Either[List[Throwable],B]]

    Definition Classes
    ManagedResourceOperations → ManagedResource
  53. def seekableProcessor: SeekableProcessor

    Definition Classes
    Seekable
  54. final def size: Option[Long]

    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.

    Definition Classes
    InputResourceInput
  55. val sizeFunc: () ⇒ Option[Long]

    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.

    Attributes
    protected
    Definition Classes
    SeekableByteChannelResourceInputResource
  56. def string(implicit codec: Codec = Codec.default): String

    Loads all the characters into memory.

    Loads all the characters into memory. There is no protection against loading very large files/amounts of data.

    codec

    The codec representing the desired encoding of the characters

    Definition Classes
    Input
  57. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  58. def tempFile(): Input with Output

    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

    Attributes
    protected
    Definition Classes
    Seekable
  59. def toByteChannelResource: InputResource[_]

    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

    Attributes
    protected
    Definition Classes
    Seekable
  60. def toString(): String

    Definition Classes
    SeekableByteChannelResource → AnyRef → Any
  61. def toTraversable[B](implicit ev: <:<[A, TraversableOnce[B]]): Traversable[B]

    Definition Classes
    ManagedResourceOperations → ManagedResource
  62. def truncate(position: Long): Unit

    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

    Definition Classes
    Seekable
  63. def truncateString(position: Long)(implicit codec: Codec = Codec.default): Unit

    Definition Classes
    Seekable
  64. def underlyingChannel(append: Boolean): CloseableOpenedResource[A]

    Attributes
    protected
    Definition Classes
    SeekableByteChannelResourceSeekable
  65. def underlyingOutput: OutputResource[WritableByteChannel]

    Attributes
    protected
    Definition Classes
    SeekableByteChannelResourceSeekableOutput
  66. def updateContext(newContext: ResourceContext): SeekableByteChannelResource[A]

    Create a Resource instance that is configured with the new ResourceContext

    Create a Resource instance that is configured with the new ResourceContext

    newContext

    A new ResourceContext

    returns

    a new instance configured with the new context

    Definition Classes
    SeekableByteChannelResourceResourceOps
  67. def updateContext(f: (ResourceContext) ⇒ ResourceContext): SeekableByteChannelResource[A]

    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

    f

    A function for transforming the current context to a new context with new values.

    returns

    a new instance configured with the new context

    Definition Classes
    ResourceOps
  68. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  71. def writableByteChannel: WritableByteChannelResource[A]

    Obtain the scalax.io.managed.WritableByteChannelResource(typically) version of this object.

    Obtain the scalax.io.managed.WritableByteChannelResource(typically) version of this object.

    returns

    the scalax.io.managed.WritableByteChannelResource(typically) version of this object.

    Definition Classes
    SeekableByteChannelResourceOutputResource
  72. def write(string: String)(implicit codec: Codec = Codec.default): Unit

    Writes a string.

    Writes a string.

    string

    the data to write

    codec

    the codec of the string to be written. The string will be converted to the encoding of sourceCodec Default is sourceCodec

    Definition Classes
    Output
  73. def write[T](data: T)(implicit writer: OutputConverter[T]): Unit

    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.

    data

    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.

    writer

    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

    Definition Classes
    Output
    See also

    #writeChars for more on writing characters

  74. def writeAppendOpen: A

  75. def writeChars(characters: TraversableOnce[Char])(implicit codec: Codec = Codec.default): Unit

    Definition Classes
    Output
  76. def writeIntsAsBytes(data: Int*): Unit

    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.

    Definition Classes
    Output
  77. def writeStrings(strings: Traversable[String], separator: String = "")(implicit codec: Codec = Codec.default): Unit

    Write several strings.

    Write several strings.

    strings

    The data to write

    separator

    A string to add between each string. It is not added to the before the first string or after the last.

    codec

    The codec of the strings to be written. The strings will be converted to the encoding of sourceCodec

    Definition Classes
    Output
  78. def writer(implicit sourceCodec: Codec): WriterResource[ChannelWriterAdapter[A]]

    Obtain the scalax.io.WriteCharsResource version of this object.

    Obtain the scalax.io.WriteCharsResource version of this object.

    sourceCodec

    the codec used to convert from bytes to characters

    returns

    the scalax.io.WriteCharsResource version of this object.

    Definition Classes
    SeekableByteChannelResourceOutputResource

Inherited from SeekableResource[A]

Inherited from OutputResource[A]

Inherited from InputResource[A]

Inherited from Resource[A]

Inherited from ManagedResourceOperations[A]

Inherited from ManagedResource[A]

Inherited from Seekable

Inherited from Output

Inherited from Input

Inherited from AnyRef

Inherited from Any

Ungrouped