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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations