<commit_before>package net.somethingdreadful.MAL;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpParams;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;

public class ImageDownloader {

	Map<String,Bitmap> imageCache;
	
	public ImageDownloader(){
		imageCache = new HashMap<String, Bitmap>();
		
	}
	
	//download function
	public void download(String url, ImageView imageView) {
	     if (cancelPotentialDownload(url, imageView)) {
	    	 
	    	 //Caching code right here
	    	 String filename = String.valueOf(url.hashCode());
	    	 File f = new File(getCacheDirectory(imageView.getContext()), filename);

	    	  // Is the bitmap in our memory cache?
	    	 Bitmap bitmap = null;
	    	 
	    	  bitmap = (Bitmap)imageCache.get(f.getPath());
	    	  
	    	  if(bitmap == null){
	    	 
	    		  bitmap = BitmapFactory.decodeFile(f.getPath());
	    		  
	    		  if(bitmap != null){
	    			  imageCache.put(f.getPath(), bitmap);
	    		  }
	    	  
	    	  }
	    	  //No? download it
	    	  if(bitmap == null){
	    		  BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
	    		  DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
	    		  imageView.setImageDrawable(downloadedDrawable);
	    		  task.execute(url);
	    	  }else{
	    		  //Yes? set the image
	    		  imageView.setImageBitmap(bitmap);
	    	  }
	     }
	}
	
	//cancel a download (internal only)
	private static boolean cancelPotentialDownload(String url, ImageView imageView) {
	    BitmapDownloaderTask bitmapDownloaderTask = getBitmapDownloaderTask(imageView);

	    if (bitmapDownloaderTask != null) {
	        String bitmapUrl = bitmapDownloaderTask.url;
	        if ((bitmapUrl == null) || (!bitmapUrl.equals(url))) {
	            bitmapDownloaderTask.cancel(true);
	        } else {
	            // The same URL is already being downloaded.
	            return false;
	        }
	    }
	    return true;
	}
	
	//gets an existing download if one exists for the imageview
	private static BitmapDownloaderTask getBitmapDownloaderTask(ImageView imageView) {
	    if (imageView != null) {
	        Drawable drawable = imageView.getDrawable();
	        if (drawable instanceof DownloadedDrawable) {
	            DownloadedDrawable downloadedDrawable = (DownloadedDrawable)drawable;
	            return downloadedDrawable.getBitmapDownloaderTask();
	        }
	    }
	    return null;<commit_msg>Added custom method to return the bitmap<commit_after>package net.somethingdreadful.MAL;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpParams;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;

public class ImageDownloader {

	Map<String,Bitmap> imageCache;
	
	public ImageDownloader(){
		imageCache = new HashMap<String, Bitmap>();
		
	}
	
	//download function
	public void download(String url, ImageView imageView) {
	     if (cancelPotentialDownload(url, imageView)) {
	    	 
	    	 //Caching code right here
	    	 String filename = String.valueOf(url.hashCode());
	    	 File f = new File(getCacheDirectory(imageView.getContext()), filename);

	    	  // Is the bitmap in our memory cache?
	    	 Bitmap bitmap = null;
	    	 
	    	  bitmap = (Bitmap)imageCache.get(f.getPath());
	    	  
	    	  if(bitmap == null){
	    	 
	    		  bitmap = BitmapFactory.decodeFile(f.getPath());
	    		  
	    		  if(bitmap != null){
	    			  imageCache.put(f.getPath(), bitmap);
	    		  }
	    	  
	    	  }
	    	  //No? download it
	    	  if(bitmap == null){
	    		  BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
	    		  DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
	    		  imageView.setImageDrawable(downloadedDrawable);
	    		  task.execute(url);
	    	  }else{
	    		  //Yes? set the image
	    		  imageView.setImageBitmap(bitmap);
	    	  }
	     }
	}
	
	public Bitmap returnDrawable(Context c, String url)
	{
		 //Caching code right here
   	 String filename = String.valueOf(url.hashCode());
   	 File f = new File(getCacheDirectory(c), filename);

   	  // Is the bitmap in our memory cache?
   	 Bitmap bitmap = null;
   	 
   	  bitmap = (Bitmap)imageCache.get(f.getPath());
   	  
   	  if(bitmap == null){
   	 
   		  bitmap = BitmapFactory.decodeFile(f.getPath());
   		  
   		  if(bitmap != null){
   			  imageCache.put(f.getPath(), bitmap);
   		  }
   	  
   	  }
   	  
   	  return bitmap;
	}
	
	//cancel a download (internal only)
	private static boolean cancelPotentialDownload(String url, ImageView imageView) {
	    BitmapDownloaderTask bitmapDownloaderTask = getBitmapDownloaderTask(imageView);

	    if (bitmapDownloaderTask != null) {
	        String bitmapUrl = bitmapDownloaderTask.url;
	        if ((bitmapUrl == null) || (!bitmapUrl.equals(url))) {
	            bitmapDownloaderTask.cancel(true);
	        } else {
	            // The same URL is already being downloaded.
	            return false;
	        }
	    }
	    return true;
	}
	
	//gets an existing download if one exists for the imageview
	private static BitmapDownloaderTask getBitmapDownloaderTask(ImageView imageView) {
	    if (imageView != null) {
	        Drawable drawable = imageView.getDrawable();
	        if (drawable instanceof DownloadedDrawable) {
	            DownloadedDrawable downloadedDrawable = (DownloadedDrawable)drawable;
	            return downloadedDrawable.getBitmapDownloaderTask();
	        }
	    }
	    return null;
{'fraction_non_alphanumeric': 0.09714285714285714, 'fraction_numerical': 0.0, 'mean_word_length': 2.9576031656302995, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 60, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5101678', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2036, 'n_words': 439}