1

I implement rest streaming and for now all works fine, but I see one problem with my implementation, when sending big amount of heavy file. For example, when I send 10 files by 100 MB in memory I have 1GB. So my question is how to implement this in modern java or by iterator?

I receive ObjectJson as InputStream and I have method when I read JSON values and get List of my domain object:

List<DomainObject> jsonStreamToDomainObject(final InputStream stream) throws IOException {
    return objectMapper.readValue(stream, new TypeReference<List<DomainObject>>() {
    });
}

So I think the method should look like below. But I think should be better solution than iterator and also I dont know how to convert Input stream to Iterator:

Iterator<DomainObject> jsonStreamToDomainObject(final InputStream stream) throws IOException {
return someMagicWithInputStream(stream);
newOne
  • 679
  • 2
  • 9
  • 27
  • Possible duplicate of [Use Jackson To Stream Parse an Array of Json Objects](https://stackoverflow.com/questions/24835431/use-jackson-to-stream-parse-an-array-of-json-objects) – rustyx Aug 02 '18 at 10:52
  • check this blog it will helpful to achieve iterator from inputstream https://www.geekality.net/2011/05/23/java-inputstream-line-iterator/ – Kumar Panchal Aug 02 '18 at 11:11

0 Answers0