mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-04-06 16:43:51 -04:00
Utils.copyToTempFile(): use try for resource management
This commit is contained in:
@@ -507,15 +507,14 @@ public class Utils {
|
||||
|
||||
public static File copyToTempFile(Context context, InputStream input, String name) throws IOException {
|
||||
File file = createTempFile(context, name);
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
byte[] buf = new byte[4096];
|
||||
int len;
|
||||
while ((len = input.read(buf)) != -1) {
|
||||
out.write(buf, 0, len);
|
||||
try (input; FileOutputStream out = new FileOutputStream(file)) {
|
||||
byte[] buf = new byte[4096];
|
||||
int len;
|
||||
while ((len = input.read(buf)) != -1) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
out.close();
|
||||
input.close();
|
||||
return file;
|
||||
}
|
||||
|
||||
public static String saveTempImage(Context context, Bitmap in, String name, Bitmap.CompressFormat format) {
|
||||
|
||||
Reference in New Issue
Block a user