aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/persistance/FileBackend.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/eu/siacs/conversations/persistance/FileBackend.java55
1 files changed, 5 insertions, 50 deletions
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java
index dbbf0a10..1cf1b26c 100644
--- a/src/eu/siacs/conversations/persistance/FileBackend.java
+++ b/src/eu/siacs/conversations/persistance/FileBackend.java
@@ -1,15 +1,10 @@
package eu.siacs.conversations.persistance;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import android.content.Context;
import android.graphics.Bitmap;
@@ -20,7 +15,7 @@ import android.util.LruCache;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
-import eu.siacs.conversations.utils.CryptoHelper;
+import eu.siacs.conversations.xmpp.jingle.JingleFile;
public class FileBackend {
@@ -43,13 +38,13 @@ public class FileBackend {
}
- public File getImageFile(Message message) {
+ public JingleFile getImageFile(Message message) {
Conversation conversation = message.getConversation();
String prefix = context.getFilesDir().getAbsolutePath();
String path = prefix + "/" + conversation.getAccount().getJid() + "/"
+ conversation.getContactJid();
String filename = message.getUuid() + ".webp";
- return new File(path + "/" + filename);
+ return new JingleFile(path + "/" + filename);
}
private Bitmap resize(Bitmap originalBitmap, int size) {
@@ -73,11 +68,11 @@ public class FileBackend {
}
}
- public File copyImageToPrivateStorage(Message message, Uri image) {
+ public JingleFile copyImageToPrivateStorage(Message message, Uri image) {
try {
InputStream is = context.getContentResolver()
.openInputStream(image);
- File file = getImageFile(message);
+ JingleFile file = getImageFile(message);
file.getParentFile().mkdirs();
file.createNewFile();
OutputStream os = new FileOutputStream(file);
@@ -89,7 +84,6 @@ public class FileBackend {
Log.d("xmppService", "couldnt compress");
}
os.close();
- message.setBody(this.createSha1(file));
return file;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
@@ -118,43 +112,4 @@ public class FileBackend {
}
return thumbnail;
}
-
- private String createSha1(final File file) {
- InputStream fis = null;
- try {
- MessageDigest digest = MessageDigest.getInstance("SHA-1");
- fis = new FileInputStream(file);
- int n = 0;
- byte[] buffer = new byte[8192];
- while (n != -1) {
- n = fis.read(buffer);
- if (n > 0) {
- digest.update(buffer, 0, n);
- }
- }
- fis.close();
- return CryptoHelper.bytesToHex(digest.digest());
- } catch (NoSuchAlgorithmException e) {
- return null;
- } catch (FileNotFoundException e) {
- if (fis!=null) {
- try {
- fis.close();
- return null;
- } catch (IOException e1) {
- return null;
- }
- }
- } catch (IOException e) {
- if (fis!=null) {
- try {
- fis.close();
- return null;
- } catch (IOException e1) {
- return null;
- }
- }
- }
- return null;
- }
}