summaryrefslogtreecommitdiffstats
path: root/bundle-plugin/src/main/scala/com/yahoo/container/plugin/util/Files.scala
blob: d32e57784da62c8942da392df1a14fe4c10ae4a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.util

import java.io.{FileOutputStream, File}
import com.yahoo.container.plugin.util.IO._

/**
 * @author  tonytv
 */
object Files {
  def allDescendantFiles(file: File): Stream[File] = {
    if (file.isFile)
      Stream(file)
    else if (file.isDirectory)
      file.listFiles().toStream.map(allDescendantFiles).flatten
    else
      Stream.empty
  }

  def withFileOutputStream[T](file: File)(f: FileOutputStream => T): T = {
    using(new FileOutputStream(file), readOnly = false)(f)
  }
}