Advertisement
happy-barney

catch example - java 02 - source

Jun 25th, 2020
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. // Example borrowed from https://github.com/nostra13/Android-Universal-Image-Loader
  2. // File: library/src/main/java/com/nostra13/universalimageloader/cache/disc/impl/ext/DiskLruCache.java
  3.  
  4.     public OutputStream newOutputStream(int index) throws IOException {
  5.         synchronized (DiskLruCache.this) {
  6.             if (entry.currentEditor != this) {
  7.                 throw new IllegalStateException();
  8.             }
  9.             if (!entry.readable) {
  10.                 written[index] = true;
  11.             }
  12.             File dirtyFile = entry.getDirtyFile(index);
  13.             FileOutputStream outputStream;
  14.             try {
  15.                 outputStream = new FileOutputStream(dirtyFile);
  16.             } catch (FileNotFoundException e) {
  17.                 // Attempt to recreate the cache directory.
  18.                 directory.mkdirs();
  19.                 try {
  20.                     outputStream = new FileOutputStream(dirtyFile);
  21.                 } catch (FileNotFoundException e2) {
  22.                     // We are unable to recover. Silently eat the writes.
  23.                     return NULL_OUTPUT_STREAM;
  24.                 }
  25.             }
  26.             return new FaultHidingOutputStream(outputStream);
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement