0

Say I have some custom file format that has some logical format defined. I'd like to "unmarshall" the "objects" from the file. Then how can I use java8 Streams in a parallel fashion to unmarshall the objects?

Is this unreasonable can you explain a more reasonable approach?

Is this not possible? If not is this possible outside of java8, or java9 or scala? Can you provide an example?

[
  abc:123,
  xy:"yz",
  s12:13,
],
...
[
  abc:1
  s:133,
]

It seems that Parallel message unmarshalling from a token delimited input stream with Java8 stream API is asking something similar but not necessarily from a file perspective. It wasn't clear to me, but I think for that issue it's not possible for java8.

Community
  • 1
  • 1
discord
  • 59
  • 10
  • 4
    Implement whatever you want using a sequential stream. *Then* think about a) whether there is any benefit from using a parallel Stream (I can’t recognize any in your question) and b) whether there’s anything preventing just turning the stream to parallel (without an implementation, it’s impossible to say) – Holger Oct 13 '16 at 10:22
  • This sounds like reasonable advice. After reading I found the following post which gives some rationale as to why reading in parallel does not provide any benefit: http://stackoverflow.com/questions/25711616/how-to-read-all-lines-of-a-file-in-parallel-in-java-8 – discord Oct 13 '16 at 16:46
  • Based on some other stack overflow posts, I believe that I can use Jacksons' JSON library to parse the javascript and using an iterator I can split the input if so desired. However I still am wondering if their is a good functional approach to this problem since the output depends on ordering of the keyset. – discord Oct 19 '16 at 21:26
  • Does it? I mean, is `abc:123, xy:"yz"` supposed to produce different results than `xy:"yz", abc:123`? Anyway, if you have something that produces an `Iterator`, there is a way to create a Stream from it, so you can chain operations. Generally, if there is an encounter order, the Stream will care to produce an appropriate *result*, even if the element *processing* may happen out-of-order. But we can’t tell you anything about the operations, you didn’t specify. All we know, is, that you have this JSON-like input and want to process it. That’s what the Jackson library already does for you… – Holger Oct 20 '16 at 08:47

0 Answers0