package com.kaltura.playersdk;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import java.util.List;

/**
 * Created by itayi on 3/5/15.
 */
public class Utilities {
    public static boolean doesPackageExist(String targetPackage, Context context){
        List<ApplicationInfo> packages;
        PackageManager pm;
        pm = context.getPackageManager();
        packages = pm.getInstalledApplications(0);

        for (ApplicationInfo packageInfo : packages) {
            if(packageInfo.packageName.equals(targetPackage)){
                return true;
            }
        }

        return false;
    }
}

@@ -142,16 +142,258 @@
 anager;%0A
+import android.net.Uri;%0Aimport android.support.annotation.NonNull;%0Aimport android.util.Log;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.net.HttpURLConnection;%0Aimport java.net.URL;
 %0Aimport 
@@ -473,16 +473,69 @@
 ities %7B%0A
+%0A    private static final String TAG = %22Utilities%22;%0A%0A
     publ
@@ -969,11 +969,1808 @@
 e;%0A    %7D
+%0A%0A    public static String readAssetToString(Context context, String asset) %7B%0A        try %7B%0A            InputStream assetStream = context.getAssets().open(asset);%0A            return fullyReadInputStream(assetStream, 1024*1024).toString();%0A        %7D catch (IOException e) %7B%0A            Log.e(TAG, %22Failed reading asset %22 + asset, e);%0A            return null;%0A        %7D%0A    %7D%0A%0A    @NonNull%0A    public static ByteArrayOutputStream fullyReadInputStream(InputStream inputStream, int byteLimit) throws IOException %7B%0A        ByteArrayOutputStream bos = new ByteArrayOutputStream();%0A        byte data%5B%5D = new byte%5B1024%5D;%0A        int count;%0A        %0A        while ((count = inputStream.read(data)) != -1) %7B%0A            int maxCount = byteLimit - bos.size();%0A            if (count %3E maxCount) %7B%0A                bos.write(data, 0, maxCount);%0A                break;%0A            %7D else %7B%0A                bos.write(data, 0, count);%0A            %7D%0A        %7D%0A        bos.flush();%0A        bos.close();%0A        inputStream.close();%0A        return bos;%0A    %7D%0A%0A    public static Uri stripLastPathSegment(Uri uri) %7B%0A        String path = uri.getPath();%0A        path = stripLastPathSegment(path);%0A        return uri.buildUpon().path(path).clearQuery().fragment(null).build();%0A    %7D%0A%0A    @NonNull%0A    public static String stripLastPathSegment(String path) %7B%0A        path = path.substring(0, path.lastIndexOf('/', path.length()-2));%0A        return path;%0A    %7D%0A%0A    public static String loadStringFromURL(Uri url, int byteLimit) throws IOException %7B%0A        HttpURLConnection conn = (HttpURLConnection) new URL(url.toString()).openConnection();%0A        conn.setRequestMethod(%22GET%22);%0A        conn.connect();%0A        InputStream is = conn.getInputStream();%0A        return fullyReadInputStream(is, byteLimit).toString();%0A    %7D
 %0A%7D%0A

Add stream-reading and URL manipulation utils.