Esempio n. 1
0
  @Override
  public boolean save(String imageUri, Bitmap bitmap) throws IOException {
    DiskLruCache.Editor editor = cache.edit(getKey(imageUri));
    if (editor == null) {
      return false;
    }

    OutputStream os = new BufferedOutputStream(editor.newOutputStream(0), bufferSize);
    boolean savedSuccessfully = false;
    try {
      savedSuccessfully = bitmap.compress(compressFormat, compressQuality, os);
    } finally {
      IoUtils.closeSilently(os);
    }
    if (savedSuccessfully) {
      editor.commit();
    } else {
      editor.abort();
    }
    return savedSuccessfully;
  }
Esempio n. 2
0
  @Override
  public boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener)
      throws IOException {
    DiskLruCache.Editor editor = cache.edit(getKey(imageUri));
    if (editor == null) {
      return false;
    }

    OutputStream os = new BufferedOutputStream(editor.newOutputStream(0), bufferSize);
    boolean copied = false;
    try {
      copied = IoUtils.copyStream(imageStream, os, listener, bufferSize);
    } finally {
      IoUtils.closeSilently(os);
      if (copied) {
        editor.commit();
      } else {
        editor.abort();
      }
    }
    return copied;
  }