| 249 | } |
| 250 | |
| 251 | public static <T> void writeObject(T object, Context context, String filename, String objectName) { |
| 252 | Closeable closable = null; |
| 253 | try { |
| 254 | FileOutputStream outputStream = context.openFileOutput(filename, Context.MODE_PRIVATE); |
| 255 | closable = outputStream; |
| 256 | |
| 257 | BufferedOutputStream bufferedStream = new BufferedOutputStream(outputStream); |
| 258 | closable = bufferedStream; |
| 259 | |
| 260 | ObjectOutputStream objectStream = new ObjectOutputStream(bufferedStream); |
| 261 | closable = objectStream; |
| 262 | |
| 263 | try { |
| 264 | objectStream.writeObject(object); |
| 265 | |
| 266 | getLogger().debug("Wrote %s: %s", objectName, object); |
| 267 | } catch (NotSerializableException e) { |
| 268 | getLogger().error("Failed to serialize %s", objectName); |
| 269 | } |
| 270 | } catch (Exception e) { |
| 271 | getLogger().error("Failed to open %s for writing (%s)", objectName, e); |
| 272 | } |
| 273 | try { |
| 274 | if (closable != null) { |
| 275 | closable.close(); |
| 276 | } |
| 277 | } catch (Exception e) { |
| 278 | getLogger().error("Failed to close %s file for writing (%s)", objectName, e); |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | public static boolean checkPermission(Context context, String permission) { |
| 283 | try { |