Class

sclib.io.fs

FSFile

Related Doc: package fs

Permalink

case class FSFile(path: Path) extends FSEntry[FSFile] with Product with Serializable

Represents a 'File'

the functions write, writeLines, append and appendLines expects a type-class instance (from Writable) for their to be written payload in scope. instances for string, char, short, int, long, float, double and some collection types are already defined (see Writable$).

the write and append functions don't add a newline at the end / between the sequences. for functions which add newlines use writeLines and appendLines.

Example:
  1. scala> import sclib.io._
    scala> for {
         |   fh <- file("/tmp/example")
         |   _ <- fh.writeLines("1. apple")                        // string
         |   _ <- fh.appendLines(List("2. banana", "3. cherry"))   // list of string
         |   _ <- fh.append(4)                                     // int
         |   _ <- fh.append('.')                                   // char
         |   _ <- fh.append(Vector(' ', 'd', 'o', 'g'))            // vector of char
         |   content <- fh.slurp
         |   _ <- fh.delete
         |
    res0: scala.util.Try[String] =
    Success(1. apple
    2. banana
    3. cherry
    4. dog)

    check the member documentation for examples

Linear Supertypes
Serializable, Serializable, Product, Equals, FSEntry[FSFile], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FSFile
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. FSEntry
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new FSFile(path: Path)

    Permalink
    Attributes
    protected[sclib.io]

Value Members

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

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. lazy val absNormalizedPath: Path

    Permalink

    absolute, normalized path

    absolute, normalized path

    Definition Classes
    FSEntry
  5. def append[A](a: A, options: Seq[OpenOption] = Seq(), cs: Charset = UTF_8)(implicit arg0: Writable[A]): Try[FSFile]

    Permalink

    appends the given content to the file

    appends the given content to the file

    the file are open with the APPEND option.

    See also

    FSFile.write

  6. def appendBytes(b: Array[Byte], options: Seq[OpenOption] = Seq()): Try[FSFile]

    Permalink

    appends the given bytes to the file

    appends the given bytes to the file

    the file are open with the APPEND option.

    See also

    FSFile.writeBytes

  7. def appendLines[A](a: A, options: Seq[OpenOption] = Seq(), cs: Charset = UTF_8)(implicit arg0: Writable[A]): Try[FSFile]

    Permalink

    appends the given content, separated with new-lines to the file

    appends the given content, separated with new-lines to the file

    the file are open with the APPEND option.

    See also

    FSFile.append

  8. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  9. def chmod(mode: String): Try[FSFile]

    Permalink

    set entry permission mode

    set entry permission mode

    mode

    : list of unix like symbolic permissions notation

    Definition Classes
    FSEntry
    Example:
    1. chmod("a=r,u+w") -> chmod(Seq(OWNER_READ, OWNER_WRITE, GROUP_READ, OTHERS_READ))
      chmod("a+x")     -> current permissions + Seq(OWNER_EXECUTE, GROUP_EXECUTE, OTHERS_EXECUTE)
  10. def chmod(n: Int): Try[FSFile]

    Permalink

    set entry permission mode

    set entry permission mode

    n

    : unix like file permission notation

    Definition Classes
    FSEntry
    Example:
    1. chmod(700) -> chmod(Seq(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE))
      chmod(644) -> chmod(Seq(OWNER_READ, OWNER_WRITE, GROUP_READ, OTHERS_READ))
  11. def chmod(perms: PosixFilePermission*): Try[FSFile]

    Permalink

    set entry permission mode

    set entry permission mode

    perms

    : sequence of http://http://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFilePermission.html

    Definition Classes
    FSEntry
    Example:
    1. scala> import java.nio.file.attribute.PosixFilePermission._
      scala> for {
           |   wd <- dir("sclib-example")
           |   wd <- wd.createTemp
           |   fh <- file(wd, "a-file").flatMap(_.create)
           |   _ <- fh.chmod(OWNER_READ)
           |   mod <- fh.lsmod
           |   _ <- wd.deleteR()
           | } yield mod
      res0: scala.util.Try[Seq[java.nio.file.attribute.PosixFilePermission]] = Success(List(OWNER_READ))
  12. def chmodR(mode: String): Try[FSFile]

    Permalink

    set entry permission mode recursive

    set entry permission mode recursive

    fail on any error

    Definition Classes
    FSEntry
    See also

    FSEntry.chmod(mode:String)*

  13. def chmodR(n: Int): Try[FSFile]

    Permalink

    set entry permission mode recursive

    set entry permission mode recursive

    fail on any error

    Definition Classes
    FSEntry
    See also

    FSEntry.chmod(n:Int)*

  14. def chmodR(perms: PosixFilePermission*): Try[FSFile]

    Permalink

    set entry permission mode recursive

    set entry permission mode recursive

    fail on any error

    Definition Classes
    FSEntry
    See also

    FSEntry.chmod(perms:java\.nio\.file\.attribute\.PosixFilePermission*)*

  15. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  16. def copy(target: FSFile, options: CopyOption*): Try[FSFile]

    Permalink

    copy the entry (file -> file, dir -> dir)

    copy the entry (file -> file, dir -> dir)

    options

    http://docs.oracle.com/javase/8/docs/api/java/nio/file/StandardCopyOption.html

    Definition Classes
    FSEntry
    Example:
    1. scala> for {
           |   wd <- dir("sclib-example")
           |   wd <- wd.createTemp
           |   src <- file(wd, "a-file")
           |   _ <- src.write("content")
           |   dst <- file(wd, "b-file")
           |   _ <- src.copy(dst)
           |   c <- dst.slurp
           |   _ <- wd.deleteR
           | } yield c
      res0: scala.util.Try[String] = Success(content)
  17. def copyTo(target: FSDir, options: CopyOption*): Try[FSFile]

    Permalink

    copy the entry to the given dir

    copy the entry to the given dir

    if the target dir doesn't exists, it's being created

    use FSEntry.copyToR(target* for a recursive copy operation

    Definition Classes
    FSEntry
  18. def copyToR(target: FSDir, options: CopyOption*): Try[FSFile]

    Permalink

    recursively copy the entry to the given dir

    recursively copy the entry to the given dir

    if the target dir doesn't exists, it's being created

    Definition Classes
    FSEntry
  19. def create(mode: String): Try[FSFile]

    Permalink

    create the filesystem entry with the given permissions

    create the filesystem entry with the given permissions

    the path hierarchy must exist - use FSEntry.mkDirs(attrs: FileAttribute*) to create the hierarchy at first.

    mode

    unix like symbolic mode

    Definition Classes
    FSEntry
    Example:
    1. create("a=r,u+w") -> create the entry with the PosixFilePermissions: OWNER_READ, OWNER_WRITE, GROUP_READ and OTHERS_READ
      scala> import scala.collection.SortedSet
      scala> for {
           |   wd <- dir("/tmp/sclib")
           |   wd <- wd.createTemp
           |   fh <- file(wd, "example")
           |   _ <- fh.create("a=r,u+wx")
           |   perm <- fh.lsmod
           |   _ <- wd.deleteR
           | } yield perm.to[SortedSet]
      res0: scala.util.Try[scala.collection.SortedSet[java.nio.file.attribute.PosixFilePermission]] = Success(TreeSet(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ, OTHERS_READ))
  20. def create(n: Int): Try[FSFile]

    Permalink

    create the filesystem entry with the given permissions

    create the filesystem entry with the given permissions

    the path hierarchy must exist - use FSEntry.mkDirs(attrs: FileAttribute*) to create the hierarchy at first.

    n

    unix like numeric mode

    Definition Classes
    FSEntry
    Example:
    1. scala> import scala.collection.SortedSet
      scala> for {
           |   wd <- dir("/tmp/sclib")
           |   wd <- wd.createTemp
           |   fh <- file(wd, "example")
           |   _ <- fh.create(740)
           |   perm <- fh.lsmod
           |   _ <- wd.deleteR
           | } yield perm.to[SortedSet]
      res0: scala.util.Try[SortedSet[java.nio.file.attribute.PosixFilePermission]] = Success(TreeSet(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, GROUP_READ))
  21. def create(perms: PosixFilePermission*): Try[FSFile]

    Permalink

    create the filesystem entry with the given permissions

    create the filesystem entry with the given permissions

    the path hierarchy must exist - use FSEntry.mkDirs(attrs:java\.nio\.file\.attribute\.FileAttribute[_]*)* to create the hierarchy at first.

    Definition Classes
    FSEntry
  22. def create: Try[FSFile]

    Permalink

    create the filesystem entry with default permissions

    create the filesystem entry with default permissions

    the path hierarchy must exist - use FSEntry.mkDirs(attrs:java\.nio\.file\.attribute\.FileAttribute[_]*)* to create the hierarchy at first.

    Definition Classes
    FSEntry
  23. def createTemp: Try[FSFile]

    Permalink

    create a new temporary filesystem entry.

    create a new temporary filesystem entry. the actual name is used for the prefix.

    if no absolute path is given, the entry is created in the temp directory (determined by: System.getProperty("java.io.tmpdir")).

    Definition Classes
    FSEntry
    Example:
    1. scala> for {
           |   fh <- dir("a-temp-dir")
           |   // override the original fh
           |   fh <- fh.createTemp
           |   _ <- fh.delete
           |   // fh.name is something like 'a-temp-dir7526811586167481701'
           | } yield fh.name.matches("a-temp-dir\\d+")
      res0: scala.util.Try[Boolean] = Success(true)
      scala> for {
           |   fh <- file("a-temp-file")
           |   // override the original fh
           |   fh <- fh.createTemp
           |   _ <- fh.delete
           |   // fh.name is something like 'a-temp-file9014711075515420555'
           | } yield fh.name.matches("a-temp-file\\d+")
      res0: scala.util.Try[Boolean] = Success(true)
      scala> for {
           |   fh <- file("a-temp-file.txt")
           |   // override the original fh
           |   fh <- fh.createTemp
           |   _ <- fh.delete
           |   // fh.name is something like 'a-temp-file2068553337840465580.txt'
           | } yield fh.name.matches("a-temp-file\\d+\\.txt")
      res1: scala.util.Try[Boolean] = Success(true)
  24. def delete(): Try[Unit]

    Permalink

    delete the file

    delete the file

    returns a Failure if the file doesn't exist.

    Definition Classes
    FSEntry
    See also

    FSEntry.deleteIfExists

  25. def deleteIfExists(): Try[Boolean]

    Permalink

    delete the file if it exists

    delete the file if it exists

    returns

    true if the file was deleted, false if it doesn't exist.

    Definition Classes
    FSEntry
  26. def depth(other: FSEntryImpl): Int

    Permalink

    relative depth to a given FSEntry

    relative depth to a given FSEntry

    Definition Classes
    FSEntry
    Example:
    1. scala> for {
           |  a <- dir("sclib-example")
           |  b <- dir(a, "x/y/z/..")
           | } yield a.depth(b)
      res0: scala.util.Try[Int] = Success(2)
  27. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  28. def exists: Boolean

    Permalink

    check if the file exists

    check if the file exists

    Definition Classes
    FSEntry
  29. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  30. def foreach(f: (String) ⇒ Unit, cs: Charset = UTF_8): Try[Unit]

    Permalink

    try to read the file line by line and execute the give function for each line

    try to read the file line by line and execute the give function for each line

    f

    function which are called for each line

  31. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  32. def isDirectory: Boolean

    Permalink

    check if the file is a directory

    check if the file is a directory

    Definition Classes
    FSEntry
  33. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  34. def isRegularFile: Boolean

    Permalink

    check if the file is a regular file

    check if the file is a regular file

    Definition Classes
    FSEntry
  35. def lines: Try[Iterator[String]]

    Permalink

  36. def lines(cs: Charset = UTF_8): Try[Iterator[String]]

    Permalink

    memory constant operation to process all lines

    memory constant operation to process all lines

    cs

    character set

    returns

    a per line iterator

  37. def lsmod: Try[Seq[PosixFilePermission]]

    Permalink

    get entry permission mode

    get entry permission mode

    Definition Classes
    FSEntry
  38. def map[A](f: (String) ⇒ A, cs: Charset = UTF_8): Try[Iterator[A]]

    Permalink

    maps a given function over every line from the given file

    maps a given function over every line from the given file

    f

    function which are called for each line

    returns

    a per line iterator where for each line the given function was applied

  39. def mkDirs: Try[FSFile]

    Permalink

  40. def mkDirs(attrs: FileAttribute[_]*): Try[FSFile]

    Permalink

    create the directories

    create the directories

    - when called on a FSDir, the directroy's path (inclusive parents) are created - when called on a FSFile the parent hierarchy are created

    attrs

    http://docs.oracle.com/javase/8/docs/api/java/nio/file/attribute/PosixFileAttributes.html

    Definition Classes
    FSEntry
  41. def move(target: FSFile, options: CopyOption*): Try[FSFile]

    Permalink

    move the entry

  42. def moveTo(dir: FSDir, options: CopyOption*): Try[FSFile]

    Permalink

    move the entry to the given directory, and keep the name

    move the entry to the given directory, and keep the name

    options

    http://docs.oracle.com/javase/8/docs/api/java/nio/file/StandardCopyOption.html

    Definition Classes
    FSEntry
  43. def mtime(millis: Long): Try[Unit]

    Permalink

    set the modification time

    set the modification time

    millis

    file modification time in milliseconds, since the epoch (1970-01-01T00:00:00Z)

    Definition Classes
    FSEntry
  44. def mtime: Try[Long]

    Permalink

    file modification time in milliseconds, since the epoch (1970-01-01T00:00:00Z)

    file modification time in milliseconds, since the epoch (1970-01-01T00:00:00Z)

    Definition Classes
    FSEntry
  45. lazy val name: String

    Permalink

    file / directory name

    file / directory name

    Definition Classes
    FSEntry
  46. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  47. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  48. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  49. val path: Path

    Permalink

    underlying path

    underlying path

    Definition Classes
    FSFileFSEntry
  50. def renameTo(newName: String, options: CopyOption*): Try[FSFile]

    Permalink

    rename the entry

    rename the entry

    options

    http://docs.oracle.com/javase/8/docs/api/java/nio/file/StandardCopyOption.html

    Definition Classes
    FSEntry
    Example:
    1. scala> for {
           |   wd <- dir("sclib-example")
           |   wd <- wd.createTemp
           |   src <- file(wd, "a-file")
           |   _ <- src.create
           |   dst <- src.renameTo("b-file")
           |   res = (src.exists, dst.exists)
           |   _ <- wd.deleteR
           | } yield res
      res0: scala.util.Try[(Boolean, Boolean)] = Success((false,true))
  51. def size: Try[Long]

    Permalink

    file size in bytes

    file size in bytes

    Definition Classes
    FSEntry
  52. def slurp: Try[String]

    Permalink

  53. def slurp(cs: Charset = UTF_8): Try[String]

    Permalink

    try to read the whole file at once and return it as a string.

    try to read the whole file at once and return it as a string.

    use sclib.io.fs.FSFile.lines(cs:java\.nio\.charset\.Charset)* for a memory constant operation.

    cs

    character set

    returns

    whole file content as a string

  54. def slurpBytes: Try[Array[Byte]]

    Permalink

    try to read the whole binary file

    try to read the whole binary file

    returns

    whole file content as a byte array

  55. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  56. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  59. def withPath(p: Path): FSFile

    Permalink
    Attributes
    protected[sclib.io.fs]
    Definition Classes
    FSFileFSEntry
  60. def write[A](a: A, options: Seq[OpenOption] = Seq(), cs: Charset = UTF_8)(implicit arg0: Writable[A]): Try[FSFile]

    Permalink

    write the given content to the file

    write the given content to the file

    when the options doesn't contain the APPEND option, the file are opened with the TRUNCATE_EXISTING option which truncate's the file before writing.

    options

    http://docs.oracle.com/javase/8/docs/api/java/nio/file/OpenOption.html

    cs

    http://docs.oracle.com/javase/8/docs/api/java/nio/charset/Charset.html

  61. def writeBytes(b: Array[Byte], options: Seq[OpenOption] = Seq()): Try[FSFile]

    Permalink

    write the given bytes to the file

    write the given bytes to the file

    when the options doesn't contain the APPEND option, the file are opened with the TRUNCATE_EXISTING option which truncate's the file before writing.

    options

    http://docs.oracle.com/javase/8/docs/api/java/nio/file/OpenOption.html

  62. def writeLines[A](a: A, options: Seq[OpenOption] = Seq(), cs: Charset = UTF_8)(implicit arg0: Writable[A]): Try[FSFile]

    Permalink

    write the given content, separated with new-lines to the file

    write the given content, separated with new-lines to the file

    See also

    FSFile.write

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from FSEntry[FSFile]

Inherited from AnyRef

Inherited from Any

Ungrouped