package com.xamoom.android.xamoomsdk.Storage;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

public class DownloadManager {
  private FileManager mFileManager;
  private ArrayList<DownloadTask> mDownloadTasks = new ArrayList<>();

  public DownloadManager(FileManager fileManager) {
    mFileManager = fileManager;
  }

  public void saveFileFromUrl(final URL url, boolean queryTasks,
                              final OnDownloadManagerCompleted completedInterface) throws MalformedURLException {
    final String urlString = url.toString();

    DownloadTask downloadTask = new DownloadTask(url, new DownloadTask.OnDownloadTaskCompleted() {
      @Override
      public void completed(ByteArrayOutputStream byteArrayOutputStream) {
        try {
          mFileManager.saveFile(urlString, byteArrayOutputStream.toByteArray());
        } catch (IOException e) {
          completedInterface.failed(urlString, new DownloadError(DownloadError.IO_EXCEPTION_ERROR_CODE,
              DownloadError.IO_EXCEPTION_ERROR, -1, null, e));
        }
        completedInterface.completed(urlString);
      }

      @Override
      public void failed(DownloadError downloadError) {
        completedInterface.failed(urlString, downloadError);
      }
    });

    if (!queryTasks) {
      downloadTask.execute();
    } else {
      mDownloadTasks.add(downloadTask);
    }
  }

  public void downloadQueriedTasks() {
    for (DownloadTask task : mDownloadTasks) {
      task.execute();
    }
  }

  public interface OnDownloadManagerCompleted {
    void completed(String urlString);
    void failed(String urlString, DownloadError downloadError);
  }

  public ArrayList<DownloadTask> getDownloadTasks() {
    return mDownloadTasks;
  }

  public void setFileManager(FileManager fileManager) {
    mFileManager = fileManager;
  }
}

@@ -962,24 +962,70 @@
 eption e) %7B%0A
+          if (completedInterface != null) %7B%0A  
           co
@@ -1126,24 +1126,26 @@
             
+  
 DownloadErro
@@ -1185,26 +1185,83 @@
 ));%0A        
+  
 %7D%0A
+        %7D%0A%0A        if (completedInterface != null) %7B%0A  
         comp
@@ -1293,24 +1293,34 @@
 urlString);%0A
+        %7D%0A
       %7D%0A%0A   
@@ -1384,24 +1384,68 @@
 oadError) %7B%0A
+        if (completedInterface != null) %7B%0A  
         comp
@@ -1493,16 +1493,26 @@
 Error);%0A
+        %7D%0A
       %7D%0A

Add nullcheck for completedInterface