Example usage for com.google.gson JsonIOException JsonIOException

List of usage examples for com.google.gson JsonIOException JsonIOException

Introduction

In this page you can find the example usage for com.google.gson JsonIOException JsonIOException.

Prototype

public JsonIOException(String msg, Throwable cause) 

Source Link

Usage

From source file:flens.Service.java

License:Apache License

private static Map<String, Object> collectConfig(String dir)
        throws JsonSyntaxException, JsonIOException, FileNotFoundException {
    List<Map<String, Object>> configs = new LinkedList<>();

    Gson g = new Gson();

    File[] files = (new File(dir)).listFiles(new FilenameFilter() {
        @Override/*w  w w .  j  a v a  2 s  .c  o  m*/
        public boolean accept(File dir, String name) {
            return name.endsWith("json");
        }
    });

    Arrays.sort(files);

    for (File f : files) {
        try {
            configs.add(g.fromJson(new FileReader(f), HashMap.class));
        } catch (Exception e) {
            throw new JsonIOException("in file: " + f.getAbsolutePath(), e);
        }
    }

    return merge(new HashMap<String, Object>(), configs);

}

From source file:tv.loilo.promise.http.ResponseJsonConverter.java

License:Apache License

@NonNull
public static JsonElement parse(@NonNull final JsonReader json) throws JsonIOException, JsonSyntaxException {
    boolean lenient = json.isLenient();
    json.setLenient(true);/* w  ww. j  a  va 2s.co  m*/
    try {
        return Streams.parse(json);
    } catch (StackOverflowError | OutOfMemoryError e) {
        throw new JsonIOException("Failed parsing JSON source: " + json + " to Json", e);
    } finally {
        json.setLenient(lenient);
    }
}