Search in sources :

Example 1 with JsonIOException

use of com.google.gson.JsonIOException in project SneakerBot by Penor.

the class Config method load.

public static ArrayList<ConfigObject> load(String name) {
    File file = new File(name);
    if (!file.exists()) {
        System.out.println(name + " does not exist; One has been created for you.");
        create(name);
        return null;
    }
    Type type = new TypeToken<ArrayList<ConfigObject>>() {
    }.getType();
    try {
        return new GsonBuilder().create().fromJson(new FileReader(name), type);
    } catch (JsonIOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonSyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : Type(java.lang.reflect.Type) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonIOException(com.google.gson.JsonIOException) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) File(java.io.File)

Example 2 with JsonIOException

use of com.google.gson.JsonIOException in project SneakerBot by Penor.

the class Credentials method load.

public static HashMap<String, CredentialObject> load(String name) {
    File file = new File(name);
    if (!file.exists()) {
        System.out.println(name + " does not exist; One has been created for you.");
        create(name);
        return null;
    }
    Type type = new TypeToken<HashMap<String, CredentialObject>>() {
    }.getType();
    try {
        return new GsonBuilder().create().fromJson(new FileReader(name), type);
    } catch (JsonIOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonSyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : Type(java.lang.reflect.Type) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonIOException(com.google.gson.JsonIOException) HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) File(java.io.File)

Example 3 with JsonIOException

use of com.google.gson.JsonIOException in project che by eclipse.

the class JsonMessageReader method next.

/**
     * Returns message parsed from JSON stream.
     *
     * @return object of class passed as parameter of constructor or null if stream is empty
     * @throws IOException if error occurs on reading stream
     */
public T next() throws IOException {
    // if not we return read byte to stream using PushbackInputStream
    if (firstRead) {
        int firstChar = reader.read();
        if (firstChar == -1) {
            return null;
        } else {
            reader.unread(firstChar);
            firstRead = false;
        }
    }
    try {
        if (streamParser.hasNext()) {
            return GSON.fromJson(streamParser.next(), messageClass);
        }
    } catch (JsonIOException e) {
        throw new IOException(e);
    } catch (JsonParseException ignore) {
    }
    return null;
}
Also used : JsonIOException(com.google.gson.JsonIOException) JsonIOException(com.google.gson.JsonIOException) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException)

Example 4 with JsonIOException

use of com.google.gson.JsonIOException in project gitblit by gitblit.

the class GitblitManager method readClientApplications.

private Collection<GitClientApplication> readClientApplications(InputStream is) {
    try {
        Type type = new TypeToken<Collection<GitClientApplication>>() {
        }.getType();
        InputStreamReader reader = new InputStreamReader(is);
        Gson gson = JsonUtils.gson();
        Collection<GitClientApplication> links = gson.fromJson(reader, type);
        return links;
    } catch (JsonIOException e) {
        logger.error("Error deserializing client applications!", e);
    } catch (JsonSyntaxException e) {
        logger.error("Error deserializing client applications!", e);
    }
    return null;
}
Also used : Type(java.lang.reflect.Type) JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStreamReader(java.io.InputStreamReader) JsonIOException(com.google.gson.JsonIOException) GitClientApplication(com.gitblit.models.GitClientApplication) Collection(java.util.Collection) Gson(com.google.gson.Gson)

Example 5 with JsonIOException

use of com.google.gson.JsonIOException in project gradle by gradle.

the class HttpPluginResolutionServiceClient method request.

private <T> Response<T> request(final String requestUrl, final Class<T> type, final Action<? super T> validator) {
    final URI requestUri = toUri(requestUrl, "plugin request");
    try {
        HttpResponseResource response = getResourceAccessor().getRawResource(requestUri, false);
        try {
            final int statusCode = response.getStatusCode();
            String contentType = response.getContentType();
            if (contentType == null || !contentType.equalsIgnoreCase(JSON)) {
                final String message = String.format("content type is '%s', expected '%s' (status code: %s)", contentType == null ? "" : contentType, JSON, statusCode);
                throw new OutOfProtocolException(requestUrl, message);
            }
            final String clientStatusChecksum = response.getHeaderValue(CLIENT_STATUS_CHECKSUM_HEADER);
            Reader reader = new InputStreamReader(response.openStream(), "utf-8");
            try {
                if (statusCode == 200) {
                    T payload = new Gson().fromJson(reader, type);
                    validator.execute(payload);
                    return new SuccessResponse<T>(payload, statusCode, requestUrl, clientStatusChecksum);
                } else if (statusCode >= 400 && statusCode < 600) {
                    ErrorResponse errorResponse = validate(requestUrl, new Gson().fromJson(reader, ErrorResponse.class));
                    return new ErrorResponseResponse<T>(errorResponse, statusCode, requestUrl, clientStatusChecksum);
                } else {
                    throw new OutOfProtocolException(requestUrl, "unexpected HTTP response status " + statusCode);
                }
            } catch (JsonSyntaxException e) {
                throw new OutOfProtocolException(requestUrl, "could not parse response JSON", e);
            } catch (JsonIOException e) {
                throw new OutOfProtocolException(requestUrl, "could not parse response JSON", e);
            }
        } finally {
            response.close();
        }
    } catch (IOException e) {
        throw ResourceExceptions.getFailed(requestUri, e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Gson(com.google.gson.Gson) IOException(java.io.IOException) JsonIOException(com.google.gson.JsonIOException) URI(java.net.URI) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonIOException(com.google.gson.JsonIOException)

Aggregations

JsonIOException (com.google.gson.JsonIOException)6 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 Type (java.lang.reflect.Type)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 GitClientApplication (com.gitblit.models.GitClientApplication)1 JsonParseException (com.google.gson.JsonParseException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HttpMessageNotWritableException (org.springframework.http.converter.HttpMessageNotWritableException)1