java - Can a stream be created from an object that has only exposed the "readNext" portion of an iterator? -


i trying read csv file, due size, without loading memory first.

the library found reading csv opencsv, works well, exposes 2 methods:

readall()  

and

readnext()  

readall out, don't want in memory @ same time, i'd use lazily read file via readnext. , ideally, i'd wrap reading via stream.

the closest i've gotten giving readnext method stream.generate construct,

stream csvdatastream = stream.generate(csvreader::readnext);  

but has massive draw of throwing error once iterator underlying csvreader exhausted. don't want wrap entire program in try/catch block because i'm using language wrong. there way create stream exposes next method?

implement spliterator. need implement tryadvance method nontrivial implementation; trysplit can return null, characteristics() can return ordered, , estimatesize can return long.max_value. call streamsupport.stream(spliterator) make stream.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -