This repository was archived by the owner on Nov 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +15
-12
lines changed
engine/src/main/java/de/gesellix/docker/response Expand file tree Collapse file tree 4 files changed +15
-12
lines changed Original file line number Diff line number Diff line change 88
99import java .io .IOException ;
1010
11- public class JsonChunksReader implements Reader {
11+ public class JsonChunksReader < T > implements Reader < T > {
1212
1313 private final JsonReader reader ;
1414 private final Moshi moshi ;
1515
1616 public JsonChunksReader (Source source ) {
17- moshi = new Moshi .Builder ().add (new CustomObjectAdapterFactory ()).build ();
18- reader = JsonReader . of ( Okio . buffer ( source ));
17+ this ( source , new Moshi .Builder ().add (new CustomObjectAdapterFactory ()).build () );
18+ }
1919
20+ public JsonChunksReader (Source source , Moshi moshi ) {
21+ this .moshi = moshi ;
22+ this .reader = JsonReader .of (Okio .buffer (source ));
2023 // For transfer-encoding: chunked:
2124 // allows repeated `readNext` calls to consume
2225 // a complete stream of JSON chunks (delimited or not).
23- reader .setLenient (true );
26+ this . reader .setLenient (true );
2427 }
2528
2629 @ Override
27- public Object readNext () throws IOException {
28- return moshi .adapter (Object . class ).fromJson (reader );
30+ public T readNext (Class < T > type ) throws IOException {
31+ return moshi .adapter (type ).fromJson (reader );
2932// return reader.readJsonValue();
3033 }
3134
Original file line number Diff line number Diff line change @@ -25,9 +25,9 @@ private Object readJsonObject(InputStream stream) throws IOException {
2525
2626 private Object readJsonObject (Source source ) throws IOException {
2727 List <Object > parsed = new ArrayList <>();
28- JsonChunksReader reader = new JsonChunksReader (source );
28+ JsonChunksReader < Object > reader = new JsonChunksReader <> (source );
2929 while (reader .hasNext ()) {
30- parsed .add (reader .readNext ());
30+ parsed .add (reader .readNext (Object . class ));
3131 }
3232
3333 if (parsed .size () == 1 ) {
Original file line number Diff line number Diff line change 66
77import java .io .IOException ;
88
9- public class LineReader implements Reader {
9+ public class LineReader implements Reader < String > {
1010
1111 private final BufferedSource buffer ;
1212
@@ -15,7 +15,7 @@ public LineReader(Source source) {
1515 }
1616
1717 @ Override
18- public Object readNext () throws IOException {
18+ public String readNext (Class < String > type ) throws IOException {
1919 return buffer .readUtf8Line ();
2020 }
2121
Original file line number Diff line number Diff line change 22
33import java .io .IOException ;
44
5- public interface Reader {
5+ public interface Reader < T > {
66
7- Object readNext () throws IOException ;
7+ T readNext (Class < T > type ) throws IOException ;
88
99 boolean hasNext () throws IOException ;
1010}
You can’t perform that action at this time.
0 commit comments