Esempio n. 1
0
 @Override
 public boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListener listener)
     throws IOException {
   File imageFile = getFile(imageUri);
   File tmpFile = new File(imageFile.getAbsolutePath() + TEMP_IMAGE_POSTFIX);
   boolean loaded = false;
   try {
     OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFile), bufferSize);
     try {
       loaded = IoUtils.copyStream(imageStream, os, listener, bufferSize);
     } finally {
       IoUtils.closeSilently(os);
     }
   } finally {
     if (loaded && !tmpFile.renameTo(imageFile)) {
       loaded = false;
     }
     if (!loaded) {
       tmpFile.delete();
     }
   }
   return loaded;
 }
Esempio n. 2
0
 @Override
 public boolean save(String imageUri, Bitmap bitmap) throws IOException {
   File imageFile = getFile(imageUri);
   File tmpFile = new File(imageFile.getAbsolutePath() + TEMP_IMAGE_POSTFIX);
   OutputStream os = new BufferedOutputStream(new FileOutputStream(tmpFile), bufferSize);
   boolean savedSuccessfully = false;
   try {
     savedSuccessfully = bitmap.compress(compressFormat, compressQuality, os);
   } finally {
     IoUtils.closeSilently(os);
     if (savedSuccessfully && !tmpFile.renameTo(imageFile)) {
       savedSuccessfully = false;
     }
     if (!savedSuccessfully) {
       tmpFile.delete();
     }
   }
   bitmap.recycle();
   return savedSuccessfully;
 }