Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove unnecessary close
  • Loading branch information
kimoonkim committed Dec 19, 2017
commit 7bc4aa28e00ae5fd93bd83d5ed4e9a1f36423261
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ object ProcessUtils extends Logging {
val proc = pb.start()
val outputLines = new ArrayBuffer[String]

Utils.tryWithResource(Source.fromInputStream(proc.getInputStream, "UTF-8")) { output =>
for (line <- output.getLines) {
Utils.tryWithResource(proc.getInputStream)(
Source.fromInputStream(_, "UTF-8").getLines().foreach { line =>
logInfo(line)
outputLines += line
}
}{
output => output.close()
}
})
assert(proc.waitFor(timeout, TimeUnit.SECONDS),
s"Timed out while executing ${fullCommand.mkString(" ")}")
assert(proc.exitValue == 0, s"Failed to execute ${fullCommand.mkString(" ")}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ object Utils extends Logging {
try f.apply(resource) finally resource.close()
}

def tryWithResource[R, T](createResource: => R)(f: R => T)(closeResource: R => T): T = {
val resource = createResource
try f.apply(resource) finally closeResource(resource)
}

def checkAndGetK8sMasterUrl(rawMasterURL: String): String = {
require(rawMasterURL.startsWith("k8s://"),
"Kubernetes master URL must start with k8s://.")
Expand Down