Created
February 11, 2020 13:06
-
-
Save SylvainHocq/db8e71eed98754d813b9bf9a984b89d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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