1

Suppose I am using dispatch to call a REST API in Scala. The API may return very large responses that don't fit the memory I have.

So I would like to read a response from the network in a fixed-size buffer and raise an exception (return an error) if the response size > the buffer size.

How can I do it with the dispatch library ?

Urist McDev
  • 498
  • 3
  • 14
Michael
  • 41,026
  • 70
  • 193
  • 341

1 Answers1

1

Use one of the stream conversion operators, such as >>, to get an input stream and check the content of the stream for length, etc.

Bob Dalgleish
  • 8,167
  • 4
  • 32
  • 42
  • Thank you. Do you have any example ? – Michael Mar 25 '14 at 20:07
  • 1
    No, I don't have an example. However the model is pretty clear. Get the input stream using any of several operators, read from the stream to the maximum length of your buffer, check the stream for remaining characters and throw an error if you would have overflowed your buffer. – Bob Dalgleish Mar 26 '14 at 17:29