Java android how Checksum a file -


what easiest way save file checksum?

in download method downloading picture url (passed string image), works fine if use testchecksum method (here in comment line) exception("no such file in directory) sure there file.

can guys me?

public class imagecacher  {           public static bitmap getimage(final context con,  final string image)throws nosuchalgorithmexception, exception {               if (patterns.web_url.matcher(image.trim()).matches()) {                  if ((imagecache.ifexist(image))) {                     toast.maketext(con.getapplicationcontext(), "image in cache", toast.length_short).show();                     return imagecache.showimage(uri.parse(image).getlastpathsegment());                  } else {                       new asynctask<void, void, boolean>() {                         protected boolean doinbackground(void... params) {                             imagecache.download(con.getapplicationcontext(), image);                              return null;                           }                      }.execute();                     toast.maketext(con.getapplicationcontext(), "image has been downloaded", toast.length_short).show();                   }                 while (imagecache.spaceinmb(imagecache.filepathfolder) > 50) {                     imagecache.deletelastmodified(imagecache.filepathfolder, con.getapplicationcontext());                 }                 //doesnt work                  //string s= testchecksum(new file (filepathfolder, (uri.parse(image).getlastpathsegment()).trim() )                   return null;             }else   toast.maketext(con.getapplicationcontext(), "please insert valid url adress", toast.length_short).show();             return null;         }     }    static string testchecksum(file outputf) throws  ioexception, nosuchalgorithmexception        {             messagedigest md5 = messagedigest.getinstance("md5");             fileinputstream fis = new fileinputstream (outputf);              byte[] data = new byte[1024];             int read = 0;             while ((read = fis.read(data)) != -1) {                 md5.update(data, 0, read);             };             byte[] hashbytes = md5.digest();              stringbuffer sb = new stringbuffer();             (int = 0; < hashbytes.length; i++) {                 sb.append(integer.tostring((hashbytes[i] & 0xff) + 0x100, 16).substring(1));              }              string filehash = sb.tostring();              return filehash;         } 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -