Created
January 30, 2018 12:59
-
-
Save thenixan/991bc410c1ea7d5cb0272e8abda7c9b2 to your computer and use it in GitHub Desktop.
This file contains 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
service.loadDataWithoutAnyParsingAtAll() | |
.flatMapObservable { responseBody -> | |
Observable.create<DataItem> { emitter -> | |
JsonReader(responseBody.charStream()) | |
.use { reader -> | |
while (reader.hasNext()) { | |
if (reader.peek() == JsonToken.BEGIN_OBJECT) { | |
reader.beginObject() | |
if (reader.nextName() == "data") { | |
reader.beginArray() | |
while (reader.hasNext() && reader.peek() != JsonToken.END_ARRAY) { | |
emitter.onNext(Gson().fromJson<DataItem>(reader, DataItem::class.java)) | |
} | |
} | |
} | |
} | |
emitter.onComplete() | |
} | |
} | |
} | |
.count() | |
.subscribe({ result -> | |
println("Size is: $result") | |
}, { error -> error.printStackTrace() }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment