Android Open Source - LCFR-Mobile-Android S3 Index Checker






From Project

Back to project page LCFR-Mobile-Android.

License

The source code is released under:

Apache License

If you think the Android project LCFR-Mobile-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.dizon.lcfrmobile;
// w  w w . j  av  a2  s  .c om
import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;
import java.util.PriorityQueue;

import org.apache.commons.codec.digest.DigestUtils;
import org.dizon.lcfr.Protocol;
import org.dizon.lcfr.ProtocolContent;
import org.dizon.lcfr.ProtocolFile;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;


public class S3IndexChecker extends AsyncTask<String, Integer, String> {

  private Context context;
  private PriorityQueue<String> downloadFiles;
  GetS3File s3;
  OnDownloadNotify notify;
  
  public S3IndexChecker(Context _context, OnDownloadNotify _notify){
    context=_context;
    downloadFiles = new PriorityQueue<String>();
    notify=_notify;
  }
  @Override
  protected String doInBackground(String... params) {
    Protocol p;
    ProtocolFile pfile;
    File file;
    for(int i=0; i<ProtocolContent.ITEMS.size(); i++){
      p=ProtocolContent.ITEMS.get(i);
      for(int j=0; j<p.getFiles().size(); j++){
        pfile = p.getFiles().get(j);
        file = context.getFileStreamPath(pfile.getFileName());
        //file = new File(pfile.getFileName());
        if(!file.exists()){
          //s3.execute(new String[]{pfile.getFileName()});
          downloadFiles.add(pfile.getFileName());
        }
        else{
          try{
            String hash = this.computeHash(file);
            String hash2 = pfile.getFileHash();
            hash = hash.toUpperCase(Locale.US);
            hash2 = hash2.toUpperCase(Locale.US);
            if(!hash.equals(hash2)){
              
              downloadFiles.add(pfile.getFileName());
            }
          }
          catch(Exception e){
            Log.d("Hash", e.toString());
          }
        }
      }
    }
    
    publishProgress(new Integer[]{0,0,downloadFiles.size()});
    ProcessQueue();
    publishProgress(new Integer[]{-1,-1,-1});
    return null;
  }
  
  @Override
  protected void onProgressUpdate(Integer... values) {
    super.onProgressUpdate(values);
    notify.UpdateProgress(values);
  }
  
  private void ProcessQueue(){
    int totalfiles=downloadFiles.size();
    int index=0;
    int progress;
    
    while(downloadFiles.size()>0){
      s3 = new GetS3File(context);
      s3.doDownload(downloadFiles.peek());
      downloadFiles.remove();
      index++;
      progress=(int) ((index/(float)totalfiles) *100);
      publishProgress(new Integer[]{progress, index, totalfiles});
    }
  }
  
  public String computeHash(File input) throws NoSuchAlgorithmException, IOException{
      byte[] demzdataz = org.apache.commons.io.FileUtils.readFileToByteArray(input);
      String hashish = DigestUtils.md5Hex(demzdataz);
      return hashish;
      /*
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
      digest.reset();
      InputStream is = null;
      DigestInputStream dis = null;
       try {
         is = new BufferedInputStream(new FileInputStream(input)); 
         dis = new DigestInputStream(is, digest);
         while(is.read()!=-1){}
        }
      catch(Exception e)
      {
      Log.d("HashFile", e.toString());
      return "";

      }
      finally
      {
        is.close();
        dis.close();
      }
        byte[] digestbytes = digest.digest();
      StringBuffer sb = new StringBuffer();

      for (int i = 0; i < digestbytes.length; i++){
        sb.append(Integer.toString((digestbytes[i] & 0xff) + 0x100, 16).substring(1));
      }
      return sb.toString();*/
  }
  
  

}




Java Source Code List

org.dizon.LCFRCAD.CADData.java
org.dizon.LCFRCAD.Calls.java
org.dizon.LCFRCAD.Pcalls.java
org.dizon.lcfr.ProtocolContent.java
org.dizon.lcfr.ProtocolFile.java
org.dizon.lcfr.ProtocolXmlParser.java
org.dizon.lcfr.Protocol.java
org.dizon.lcfrmobile.GetS3File.java
org.dizon.lcfrmobile.HttpTeste.java
org.dizon.lcfrmobile.IncidentDetailActivity.java
org.dizon.lcfrmobile.IncidentDetailFragment.java
org.dizon.lcfrmobile.IncidentListActivity.java
org.dizon.lcfrmobile.IncidentListFragment.java
org.dizon.lcfrmobile.MainActivity.java
org.dizon.lcfrmobile.MainDisplayFragment.java
org.dizon.lcfrmobile.OnDownloadNotify.java
org.dizon.lcfrmobile.ProtocolDetailActivity.java
org.dizon.lcfrmobile.ProtocolDetailFragment.java
org.dizon.lcfrmobile.ProtocolListActivity.java
org.dizon.lcfrmobile.ProtocolListFragment.java
org.dizon.lcfrmobile.S3IndexChecker.java
org.dizon.lcfrmobile.SettingsActivity.java
org.dizon.lcfrmobile.dummy.DummyContent.java