screenshot plugin: fix okhttp resource leak on imgur upload

This commit is contained in:
UniquePassive
2018-01-30 18:45:57 +01:00
parent c157c0df75
commit ad90e932c6

View File

@@ -422,21 +422,23 @@ public class ScreenshotPlugin extends Plugin
@Override
public void onResponse(Call call, Response response) throws IOException
{
InputStream in = response.body().byteStream();
ImageUploadResponse imageUploadResponse = RuneLiteAPI.GSON
.fromJson(new InputStreamReader(in), ImageUploadResponse.class);
if (imageUploadResponse.isSuccess())
try (InputStream in = response.body().byteStream())
{
String link = imageUploadResponse.getData().getLink();
ImageUploadResponse imageUploadResponse = RuneLiteAPI.GSON
.fromJson(new InputStreamReader(in), ImageUploadResponse.class);
StringSelection selection = new StringSelection(link);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
if (config.notifyWhenTaken())
if (imageUploadResponse.isSuccess())
{
notifier.notify("A screenshot was uploaded and inserted into your clipboard!", TrayIcon.MessageType.INFO);
String link = imageUploadResponse.getData().getLink();
StringSelection selection = new StringSelection(link);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
if (config.notifyWhenTaken())
{
notifier.notify("A screenshot was uploaded and inserted into your clipboard!", TrayIcon.MessageType.INFO);
}
}
}
}