Package org.openhab.core.io.rest
Class Stream2JSONInputStream
java.lang.Object
java.io.InputStream
org.openhab.core.io.rest.Stream2JSONInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,JSONInputStream
@NonNullByDefault
public class Stream2JSONInputStream
extends InputStream
implements JSONInputStream
This
InputStream will stream Streams as JSON one item at a time. This will reduce memory usage when
streaming large collections through the REST interface. The input stream creates one JSON representation at a time
from the top level elements of the stream. For best performance a flattened stream should be provided. Otherwise a
nested collections JSON representation will be fully transformed into memory.- Author:
- Henning Treu - Initial contribution, Jörg Sautter - Use as SequenceInputStream to simplify the logic
-
Constructor Summary
ConstructorsConstructorDescriptionStream2JSONInputStream(Stream<?> source) Creates a newStream2JSONInputStreambacked by the givenStreamsource. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intread()intread(byte @Nullable [] b, int off, int len) longtransferTo(OutputStream target) Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes
-
Constructor Details
-
Stream2JSONInputStream
Creates a newStream2JSONInputStreambacked by the givenStreamsource.- Parameters:
source- theStreambacking this input stream. Must not be null.
-
-
Method Details
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
transferTo
- Overrides:
transferToin classInputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-