scalax.file

FileOps

abstract class FileOps extends Seekable

An object for reading and writing files. FileOps provides access to Channels and streams as well as providing methods for performing simple tasks on files easily.

Obtaining a FileOps from a object does not open a file execution of methods will open a file. Thus it is important to handle NotFileException and FileNotFoundException. Depending on the method one or both exceptions must be handled.

Examples of exception handling:


 try {
  file.lines flatMap _.split(":")
 } catch {
  case FileNotFoundException => fail
  case NotFileException => fail
 }

or using the Exceptions object

import scala.util.control.Exceptions
val catcher = catching(classOf[NotFileException], classOf[FileNotFoundException])

catcher {
  file.lines flatMap _.split(":")
}

The API into 3 main sections

open() attempts to perform all actions using the open channel in order to improve the performance of the operations.

lock() performs all the actions using the same channel

Self Type
Path
Since

1.0

Linear Supertypes
Seekable, Output, Input, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. FileOps
  2. Seekable
  3. Output
  4. Input
  5. AnyRef
  6. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new FileOps()

Abstract Value Members

  1. abstract def channel(openOptions: OpenOption*): SeekableByteChannelResource[SeekableByteChannel]

    Obtains a ByteChannel for read/write access to the file.

    Obtains a ByteChannel for read/write access to the file. If no OpenOptions are specified the underlying file will be opened with read/write/create/truncate options.

    The Resource will be configured with the associated fileSystem's ResourceContext

    All OpenOption can be used

    openOptions

    the options that define how the file is opened when using the stream Default is options only

  2. abstract def context: ResourceContext

    Definition Classes
    Seekable → Input
  3. abstract def fileChannel(openOptions: OpenOption*): Option[SeekableByteChannelResource[SeekableByteChannel]]

    Obtains a FileChannel for read/write access to the file.

    Obtains a FileChannel for read/write access to the file. Not all filesystems can support FileChannels therefore None will be returned if the filesystem does not support FileChannels. If no OpenOptions are specified the underlying file will be opened with read/write/create/truncate options

    All OpenOption can be used

    The Resource will be configured with the associated fileSystem's ResourceContext

    openOptions

    the options that define how the file is opened when using the stream Default is read/write/create/truncate

  4. abstract def inputStream(): InputStreamResource[InputStream]

    Obtains an input stream resource for reading from the file

    Obtains an input stream resource for reading from the file

    The Resource will be configured with the associated fileSystem's ResourceContext

  5. abstract def outputStream(openOptions: OpenOption*): OutputStreamResource[OutputStream]

    Obtains an OutputStreamResource for writing to the file

    Obtains an OutputStreamResource for writing to the file

    The Resource will be configured with the associated fileSystem's ResourceContext

    All OpenOption can be used except Read which will be ignored if present

    openOptions

    the options that define how the file is opened when using the stream The Write option is implicitly added to the set of options Default is write/create/truncate

  6. abstract def size: Option[Long]

    Definition Classes
    Input
  7. abstract def withLock[R](start: Long = 0, size: Long = 1, shared: Boolean = false, context: ResourceContext = fileSystem.context)(block: (Seekable) ⇒ R): Option[R]

    Performs an operation on the file with a FileLock

    Performs an operation on the file with a FileLock

    Not all filesystems support locking. If not then None will be returned by the method

    The defaults will lock the entire file with an exclusive lock. It is possible to modify the lock so that it only locks part of the file and may be a shared lock. Not all filesystems support shared locks but if that is the case the lock will automatically be upgraded to a exclusiveLock

    The semantics of this locking behavious are very similar to those in the java.nio.channels.FileLock It is recommended that those javadocs are read and the warnings present in those docs are followed.

    start

    the start position of the lock. Must be a non-negative Long

    size

    the length in bits the lock. If -1 then the entire file from start to the end will be locked

    shared

    If true then a shared lock will be obtained if possible. If shared locks are not supported then an exclusive lock will be obtained

    context

    The context for controlling buffer sizes error handling and other low level configuration

    returns

    the result the result from the block or None if the filesystem does not support locking

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

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

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

    Definition Classes
    AnyRef → Any
  4. def append(string: String)(implicit codec: Codec): Unit

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

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

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

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

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

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

    Definition Classes
    Seekable → Input
  11. def byteArray: Array[Byte]

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

    Definition Classes
    Seekable → Input
  13. def bytesAsInts: LongTraversable[Int]

    Definition Classes
    Seekable → Input
  14. def chars(implicit codec: Codec): LongTraversable[Char]

    Definition Classes
    FileOps → Seekable → Input
  15. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  16. def copyDataTo(output: Output): Unit

    Definition Classes
    Input
  17. def doCopyFrom(input: Input): Unit

    Attributes
    protected
    Definition Classes
    Output
  18. final def eq(arg0: AnyRef): Boolean

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

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

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  21. final def getClass(): Class[_]

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

    Definition Classes
    AnyRef → Any
  23. def insert[T](position: Long, data: T)(implicit converter: OutputConverter[T]): Any

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

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

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

    Definition Classes
    Any
  27. def lines(terminator: Terminator, includeTerminator: Boolean)(implicit codec: Codec): LongTraversable[String]

    Definition Classes
    Input
  28. final def ne(arg0: AnyRef): Boolean

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

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

    Definition Classes
    AnyRef
  31. def outputProcessor: OutputProcessor

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

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

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

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

    Attributes
    protected
    Definition Classes
    Seekable
  36. def seekableProcessor(openOptions: Seq[OpenOption] = List(Read,Write), context: ResourceContext = fileSystem.context): SeekableProcessor

    Runs several operations as efficiently as possible.

    Runs several operations as efficiently as possible. If the filesystem permits random access then the same channel will be used to perform all operations.

    Note: only the direct file operations (bytes,lines,write,patch etc...) can be used and expected to use the same resource. The resource methods all created new streams.

    Note: not all file systems support this, if not then at worst the performance is the same as if they where performed outside an open block

    openOptions

    The options that define how the file is opened for the duration of the operation Default is Write/Create/Truncate

    context

    The context for controlling buffer sizes error handling and other low level configuration defaults to filesystem Resource context

  37. def seekableProcessor: SeekableProcessor

    Definition Classes
    Seekable
  38. def string(implicit codec: Codec): String

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

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

    Attributes
    protected
    Definition Classes
    Seekable
  41. def toByteChannelResource(): InputResource[ByteChannel]

    Attributes
    protected
    Definition Classes
    FileOps → Seekable
  42. def toString(): String

    Definition Classes
    AnyRef → Any
  43. def truncate(position: Long): Unit

    Definition Classes
    Seekable
  44. def truncateString(position: Long)(implicit codec: Codec): Unit

    Definition Classes
    Seekable
  45. def underlyingChannel(append: Boolean): OpenedResource[SeekableByteChannel]

    Attributes
    protected
    Definition Classes
    FileOps → Seekable
  46. def underlyingOutput: OutputResource[WritableByteChannel]

    Attributes
    protected
    Definition Classes
    FileOps → Seekable → Output
  47. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  50. def write(string: String)(implicit codec: Codec): Unit

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

    Definition Classes
    Output
  52. def writeChars(characters: TraversableOnce[Char])(implicit codec: Codec): Unit

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

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

    Definition Classes
    Output

Inherited from Seekable

Inherited from Output

Inherited from Input

Inherited from AnyRef

Inherited from Any

Ungrouped