use of com.jockie.bot.core.utility.function.TriConsumer in project Sx4 by sx4-discord-bot.
the class EmoteCommand method getBytes.
private void getBytes(OkHttpClient httpClient, String url, TriConsumer<byte[], Boolean, Integer> bytes) {
Request request = new Request.Builder().url(RequestUtility.getWorkerUrl(url)).build();
httpClient.newCall(request).enqueue((HttpCallback) response -> {
if (response.code() == 200) {
String contentType = response.header("Content-Type"), extension = null;
if (contentType != null && contentType.contains("/")) {
extension = contentType.split("/")[1].toLowerCase();
}
bytes.accept(response.body().bytes(), extension == null ? null : extension.equals("gif"), 200);
return;
} else if (response.code() == 415) {
int periodIndex = url.lastIndexOf('.');
if (periodIndex != -1) {
String extension = url.substring(periodIndex + 1);
if (extension.equalsIgnoreCase("gif")) {
this.getBytes(httpClient, url.substring(0, periodIndex + 1) + "png", bytes);
return;
}
}
}
bytes.accept(null, null, response.code());
});
}
Aggregations