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);