[Android] Code factorization
Geoffrey Métais
git at videolan.org
Tue Sep 5 17:20:53 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Sep 5 14:41:08 2017 +0200| [108d27ba3ad5fe2bdc87f5816929d202a49fe68b] | committer: Geoffrey Métais
Code factorization
> https://code.videolan.org/videolan/vlc-android/commit/108d27ba3ad5fe2bdc87f5816929d202a49fe68b
---
libvlc/src/org/videolan/libvlc/util/VLCUtil.java | 37 +++++++++---------------
1 file changed, 13 insertions(+), 24 deletions(-)
diff --git a/libvlc/src/org/videolan/libvlc/util/VLCUtil.java b/libvlc/src/org/videolan/libvlc/util/VLCUtil.java
index ce0d23cdb..ba2db7ae2 100644
--- a/libvlc/src/org/videolan/libvlc/util/VLCUtil.java
+++ b/libvlc/src/org/videolan/libvlc/util/VLCUtil.java
@@ -32,6 +32,7 @@ import org.videolan.libvlc.LibVLC;
import org.videolan.libvlc.Media;
import java.io.BufferedReader;
+import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
@@ -170,14 +171,8 @@ public class VLCUtil {
}
} catch (IOException ignored) {
} finally {
- if (br != null)
- try {
- br.close();
- } catch (IOException e) {}
- if (fileReader != null)
- try {
- fileReader.close();
- } catch (IOException e) {}
+ close(br);
+ close(fileReader);
}
if (processors == 0)
processors = 1; // possibly borked cpuinfo?
@@ -243,14 +238,8 @@ public class VLCUtil {
Log.w(TAG, "Could not parse maximum CPU frequency!");
Log.w(TAG, "Failed to parse: " + line);
} finally {
- if (br != null)
- try {
- br.close();
- } catch (IOException ignored) {}
- if (fileReader != null)
- try {
- fileReader.close();
- } catch (IOException ignored) {}
+ close(br);
+ close(fileReader);
}
// Store into MachineSpecs
@@ -372,16 +361,10 @@ public class VLCUtil {
return null;
}
return elf;
- } catch (FileNotFoundException e) {
- e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
- try {
- if (in != null)
- in.close();
- } catch (IOException e) {
- }
+ close(in);
}
return null;
}
@@ -566,7 +549,6 @@ public class VLCUtil {
else
sb.append(c);
}
-
return sb.toString();
}
@@ -592,5 +574,12 @@ public class VLCUtil {
return nativeGetThumbnail(media, i_width, i_height);
}
+ private static void close(Closeable closeable) {
+ if (closeable != null)
+ try {
+ closeable.close();
+ } catch (IOException ignored) {}
+ }
+
private static native byte[] nativeGetThumbnail(Media media, int i_width, int i_height);
}
More information about the Android
mailing list