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 Stream
s 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
ConstructorDescriptionStream2JSONInputStream
(Stream<?> source) Creates a newStream2JSONInputStream
backed by the givenStream
source. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
int
read()
int
read
(byte @Nullable [] b, int off, int len) long
transferTo
(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 newStream2JSONInputStream
backed by the givenStream
source.- Parameters:
source
- theStream
backing this input stream. Must not be null.
-
-
Method Details
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
transferTo
- Overrides:
transferTo
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-