Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputStreamOps#asString doesn't close the stream on exception #198

Closed
liff opened this issue Nov 27, 2017 · 0 comments
Closed

InputStreamOps#asString doesn't close the stream on exception #198

liff opened this issue Nov 27, 2017 · 0 comments
Labels

Comments

@liff
Copy link

liff commented Nov 27, 2017

This will leak a file handle:

import java.io.{File => JFile, FileInputStream}
import better.files._

class BrokenFileInputStream(file: JFile) extends FileInputStream(file) {
  override def read(b: Array[Byte]): Int = throw new Exception("ouch")
}

val stream = new BrokenFileInputStream(new JFile("hello.txt")) // assuming hello.txt exists
stream.asString(closeStream = true)

Saying closeStream = true means the stream should be closed regardless of whether there was an exception or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants