Merge pull request #502 from UniquePassive/screenshot-resleak

screenshot plugin: fix okhttp resource leak on imgur upload
This commit is contained in:
Adam
2018-01-31 18:08:22 -05:00
committed by GitHub

View File

@@ -430,21 +430,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);
}
}
}
}