diff --git a/app/src/main/java/ru/vtosters/lite/utils/IOUtils.java b/app/src/main/java/ru/vtosters/lite/utils/IOUtils.java index a0b7db6e3..d736f16e0 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/IOUtils.java +++ b/app/src/main/java/ru/vtosters/lite/utils/IOUtils.java @@ -26,7 +26,10 @@ public class IOUtils { public static byte[] decodeStream(InputStream encIs, String keyURL) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException, IOException { CipherInputStream cip = new CipherInputStream(encIs, getCipher(keyURL)); - return readAllBytes(cip); + var bytes = readAllBytes(cip); + cip.close(); + + return bytes; } public static Cipher getCipher(String key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException { @@ -46,7 +49,11 @@ public class IOUtils { } public static String readAllLines(File file) throws IOException { - return readAllLines(new FileInputStream(file)); + var is = new FileInputStream(file); + var bytes = readAllBytes(is); + is.close(); + + return new String(bytes, StandardCharsets.UTF_8); } public static String readAllLines(InputStream is) throws IOException { @@ -54,7 +61,11 @@ public class IOUtils { } public static byte[] readAllBytes(File file) throws IOException { - return readAllBytes(new FileInputStream(file)); + var is = new FileInputStream(file); + var bytes = readAllBytes(is); + is.close(); + + return bytes; } public static byte[] readAllBytes(InputStream is) throws IOException { @@ -63,7 +74,11 @@ public class IOUtils { int len; while ((len = is.read(buffer)) > 0) bos.write(buffer, 0, len); - return bos.toByteArray(); + + var bytes = bos.toByteArray(); + bos.close(); + + return bytes; } public static void writeToFile(File file, String content) throws IOException { @@ -73,6 +88,7 @@ public class IOUtils { public static void writeToFile(File file, byte[] content) throws IOException { FileOutputStream fos = new FileOutputStream(file); fos.write(content); + fos.close(); } public static void deleteRecursive(File f) {