[FIX] Закрываем ресурсы в LauncherAgent.

This commit is contained in:
Zaxar163 2019-04-10 10:17:43 +03:00
parent 3f4d857e27
commit de2e53dfc2
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B

View file

@ -147,13 +147,14 @@ private static byte[] transformClass(String className, byte[] classBytes) {
* @throws IOException
*/
private static byte[] getClassFile(Class<?> clazz) throws IOException {
InputStream is = clazz.getResourceAsStream( "/" + clazz.getName().replace('.', '/') + ".class");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int r = 0;
byte[] buffer = new byte[8192];
while((r=is.read(buffer))>=0) {
baos.write(buffer, 0, r);
}
return baos.toByteArray();
try (InputStream is = clazz.getResourceAsStream( "/" + clazz.getName().replace('.', '/') + ".class");
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
int r = 0;
byte[] buffer = new byte[8192];
while((r=is.read(buffer))>=0) {
baos.write(buffer, 0, r);
}
return baos.toByteArray();
}
}
}