com.dslplatform.json
Class JsonStreamReader<TContext>

java.lang.Object
  extended by com.dslplatform.json.JsonReader<TContext>
      extended by com.dslplatform.json.JsonStreamReader<TContext>
Type Parameters:
TContext - context passed to deserialized object instances

public final class JsonStreamReader<TContext>
extends JsonReader<TContext>

Object for processing JSON from InputStream. DSL-JSON works on byte level (instead of char level). Deserialized instances can obtain TContext information provided with this reader.

Stream reader works by partially processing JSON in chunks.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.dslplatform.json.JsonReader
JsonReader.ReadJsonObject<T extends JsonObject>, JsonReader.ReadObject<T>
 
Field Summary
 
Fields inherited from class com.dslplatform.json.JsonReader
buffer, chars, context, currentIndex, currentPosition
 
Constructor Summary
JsonStreamReader(InputStream stream, byte[] buffer, TContext context)
          Create reusable stream reader.
 
Method Summary
<T extends JsonObject>
Iterator<T>
iterateOver(JsonReader.ReadJsonObject<T> reader)
           
<T> Iterator<T>
iterateOver(JsonReader.ReadObject<T> reader)
           
 byte read()
          Read next byte from JSON input (buffer/stream).
 byte[] readBase64()
           
static int readFully(byte[] buffer, InputStream stream, int offset)
          Populate buffer until the end of buffer or stream.
 void reset(InputStream stream)
          Prepare JsonStreamReader for processing another stream.
 
Methods inherited from class com.dslplatform.json.JsonReader
calcHash, checkArrayEnd, deserializeCollection, deserializeCollection, deserializeCollection, deserializeCollection, deserializeNullableCollection, deserializeNullableCollection, deserializeNullableCollection, deserializeNullableCollection, fillName, getCurrentIndex, getLastName, getNextToken, getTokenStart, last, length, positionInStream, positionInStream, readKey, readNext, readNumber, readSimpleQuote, readSimpleString, readString, scanNumber, skip, toString, wasFalse, wasLastName, wasNull, wasTrue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonStreamReader

public JsonStreamReader(InputStream stream,
                        byte[] buffer,
                        TContext context)
                 throws IOException
Create reusable stream reader. Prefer creating stream reader through DslJson#newReader since it will pass several arguments (such as key/string value cache) First chunk will be populated. First byte will not be read. It will allocate new char[64] for string buffer

Parameters:
stream - input stream to read from
buffer - buffer to hold chunk of stream
context - available context
Throws:
IOException - unable to read from stream
Method Detail

readFully

public static int readFully(byte[] buffer,
                            InputStream stream,
                            int offset)
                     throws IOException
Populate buffer until the end of buffer or stream.

Parameters:
buffer - buffer to fill
stream - stream to read
offset - populate buffer after specified offset
Returns:
how many bytes have been read
Throws:
IOException - unable to read from stream

reset

public void reset(InputStream stream)
           throws IOException
Prepare JsonStreamReader for processing another stream. First chunk will be populated. First byte will not be read.

Parameters:
stream - new stream to process
Throws:
IOException - unable to read from stream

read

public byte read()
          throws IOException
Read next byte from JSON input (buffer/stream). If buffer has been processed, fill the buffer with next chunk; otherwise get next byte from the buffer

Overrides:
read in class JsonReader<TContext>
Returns:
next byte to process
Throws:
IOException - unable to read from stream

readBase64

public byte[] readBase64()
                  throws IOException
Overrides:
readBase64 in class JsonReader<TContext>
Throws:
IOException

iterateOver

public <T> Iterator<T> iterateOver(JsonReader.ReadObject<T> reader)
                        throws IOException
Throws:
IOException

iterateOver

public <T extends JsonObject> Iterator<T> iterateOver(JsonReader.ReadJsonObject<T> reader)
                                           throws IOException
Throws:
IOException


Copyright © 2017. All rights reserved.