Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SylvainHocq/db8e71eed98754d813b9bf9a984b89d2 to your computer and use it in GitHub Desktop.
Save SylvainHocq/db8e71eed98754d813b9bf9a984b89d2 to your computer and use it in GitHub Desktop.
fun getReadLinesObservable(ctx: Context, fileName: String): Observable<String> {
return Observable
.create { emitter:Emitter<String> ->
val input: BufferedReader
try {
val open = ctx.assets.open(fileName)
input = BufferedReader(InputStreamReader(open))
var line = input.readLine()
while (line != null) {
emitter.onNext(line)
line = input.readLine()
}
emitter.onComplete()
} catch (e: Exception) {
e.printStackTrace()
emitter.onError(e)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment