Datasets:
ArXiv:
License:
Download data/val/jesusbmx/HttpCli/src/httpcli/adapter/gson/RespBodyGson.java from RepoFusion/Stack-Repo: direct link, hf CLI and curl.
- Browser
- Download file 991 Bytes
-
https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/main/data/val/jesusbmx/HttpCli/src/httpcli/adapter/gson/RespBodyGson.java
- Command line
-
hf download hf://datasets/RepoFusion/Stack-Repo/data/val/jesusbmx/HttpCli/src/httpcli/adapter/gson/RespBodyGson.java
-
curl -L -o RespBodyGson.java https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/main/data/val/jesusbmx/HttpCli/src/httpcli/adapter/gson/RespBodyGson.java
991 Bytes
| package httpcli.adapter.gson; | |
| import com.google.gson.Gson; | |
| import com.google.gson.JsonIOException; | |
| import com.google.gson.TypeAdapter; | |
| import com.google.gson.stream.JsonReader; | |
| import com.google.gson.stream.JsonToken; | |
| import httpcli.ResponseBody; | |
| import httpcli.adapter.RespBodyAdapter; | |
| public class RespBodyGson<T> implements RespBodyAdapter<T> { | |
| public final Gson gson; | |
| public final TypeAdapter<T> adapter; | |
| public RespBodyGson(Gson gson, TypeAdapter<T> adapter) { | |
| this.gson = gson; | |
| this.adapter = adapter; | |
| } | |
| public T parse(ResponseBody respBody) throws Exception { | |
| JsonReader jsonReader = gson.newJsonReader(respBody.charStream()); | |
| try { | |
| T result = adapter.read(jsonReader); | |
| if (jsonReader.peek() != JsonToken.END_DOCUMENT) { | |
| throw new JsonIOException("JSON document was not fully consumed."); | |
| } | |
| return result; | |
| } finally { | |
| respBody.close(); | |
| } | |
| } | |
| } | |