package co.chatsdk.core.utils;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import co.chatsdk.core.session.ChatSDK;

/**
 * Created by ben on 5/17/18.
 */

public class FileUtils {

    public static byte [] fileToBytes (File file) {
        int size = (int) file.length();
        byte[] bytes = new byte[size];
        try {
            BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
            buf.read(bytes, 0, bytes.length);
            buf.close();
        } catch (IOException e) {
            ChatSDK.logError(e);
        }
        return bytes;
    }

}

@@ -36,26 +36,194 @@
 ort 
-java.io.BufferedIn
+android.content.Context;%0Aimport android.database.Cursor;%0Aimport android.net.Uri;%0Aimport android.provider.OpenableColumns;%0A%0Aimport java.io.BufferedInputStream;%0Aimport java.io.ByteArrayOut
 putS
@@ -309,16 +309,44 @@
 ception;
+%0Aimport java.io.InputStream;
 %0A%0Aimport
@@ -828,16 +828,16 @@
       %7D%0A
-
         
@@ -857,10 +857,1461 @@
 %0A    %7D%0A%0A
+    public static byte %5B%5D fileToBytes (Context context, Uri uri) %7B%0A        try %7B%0A            InputStream inputStream = context.getContentResolver().openInputStream(uri);%0A            if (inputStream != null) return readBytes(inputStream);%0A        %7D catch (IOException e) %7B%0A            ChatSDK.logError(e);%0A        %7D%0A        return null;%0A    %7D%0A%0A    public static byte%5B%5D readBytes(InputStream inputStream) throws IOException %7B%0A        ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();%0A        int bufferSize = 1024;%0A        byte%5B%5D buffer = new byte%5BbufferSize%5D;%0A        int len = 0;%0A        while ((len = inputStream.read(buffer)) != -1) %7B%0A            byteBuffer.write(buffer, 0, len);%0A        %7D%0A        return byteBuffer.toByteArray();%0A    %7D%0A%0A    public static String getFileName(Context context, Uri uri) %7B%0A        String result = null;%0A        if (uri.getScheme().equals(%22content%22)) %7B%0A            try (Cursor cursor = context.getContentResolver().query(uri, null, null, null, null)) %7B%0A                if (cursor != null && cursor.moveToFirst()) %7B%0A                    result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));%0A                %7D%0A            %7D%0A        %7D%0A        if (result == null) %7B%0A            result = uri.getPath();%0A            int cut = result.lastIndexOf('/');%0A            if (cut != -1) %7B%0A                result = result.substring(cut + 1);%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A
 %7D%0A

Add support to read file from Uri (#338)