aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-11-15 15:43:04 +0100
committerDaniel Gultsch <daniel@gultsch.de>2016-11-15 15:43:04 +0100
commite84af512729cafa43ed831540d4406e1bb913689 (patch)
tree9044918a02dfc7449f526f99d2f4636ed28bb71a /src/main/java/eu/siacs/conversations/persistance/FileBackend.java
parentd61b00604d9a04c7f4a3933e42eee746583ba643 (diff)
distinguish between general i/o error and write exception when copying files
Diffstat (limited to 'src/main/java/eu/siacs/conversations/persistance/FileBackend.java')
-rw-r--r--src/main/java/eu/siacs/conversations/persistance/FileBackend.java25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
index bc919788..1886d3c0 100644
--- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java
@@ -54,6 +54,7 @@ import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.ExifHelper;
import eu.siacs.conversations.utils.FileUtils;
+import eu.siacs.conversations.utils.FileWriterException;
import eu.siacs.conversations.xmpp.pep.Avatar;
public class FileBackend {
@@ -238,11 +239,21 @@ public class FileBackend {
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0) {
- os.write(buffer, 0, length);
+ try {
+ os.write(buffer, 0, length);
+ } catch (IOException e) {
+ throw new FileWriterException();
+ }
+ }
+ try {
+ os.flush();
+ } catch (IOException e) {
+ throw new FileWriterException();
}
- os.flush();
} catch(FileNotFoundException e) {
throw new FileCopyException(R.string.error_file_not_found);
+ } catch(FileWriterException e) {
+ throw new FileCopyException(R.string.error_unable_to_create_temporary_file);
} catch (IOException e) {
e.printStackTrace();
throw new FileCopyException(R.string.error_io_exception);
@@ -287,8 +298,13 @@ public class FileBackend {
InputStream is = null;
OutputStream os = null;
try {
- file.createNewFile();
+ if (!file.exists() && !file.createNewFile()) {
+ throw new FileCopyException(R.string.error_unable_to_create_temporary_file);
+ }
is = mXmppConnectionService.getContentResolver().openInputStream(image);
+ if (is == null) {
+ throw new FileCopyException(R.string.error_not_an_image_file);
+ }
Bitmap originalBitmap;
BitmapFactory.Options options = new BitmapFactory.Options();
int inSampleSize = (int) Math.pow(2, sampleSize);
@@ -315,7 +331,6 @@ public class FileBackend {
quality -= 5;
}
scaledBitmap.recycle();
- return;
} catch (FileNotFoundException e) {
throw new FileCopyException(R.string.error_file_not_found);
} catch (IOException e) {
@@ -330,8 +345,6 @@ public class FileBackend {
} else {
throw new FileCopyException(R.string.error_out_of_memory);
}
- } catch (NullPointerException e) {
- throw new FileCopyException(R.string.error_io_exception);
} finally {
close(os);
close(is);