Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The file request should always come with a MD5 checksum. If you have an MD5 header then all you need to do is check that against the files generated MD5. Then your done, its better to do it this way as you can have a file with the same number of bytes but one byte gets garbled in transmission.</p> <pre><code> entity.writeTo(new FileOutputStream(outfile)); String md5 = response.getHeaders("Content-MD5")[0].getValue(); byte[] b64 = Base64.decode(md5, Base64.DEFAULT); String sB64 = IntegrityUtils.toASCII(b64, 0, b64.length); if (outfile.exists()) { String orgMd5 = null; try { orgMd5 = IntegrityUtils.getMD5Checksum(outfile); } catch (Exception e) { Log.d(TAG,"Exception in file hex..."); } if (orgMd5 != null &amp;&amp; orgMd5.equals(sB64)) { Log.d(TAG,"MD5 is equal to files MD5"); } else { Log.d(TAG,"MD5 does not equal files MD5"); } } </code></pre> <p>Add this class to your project:</p> <pre><code>public class IntegrityUtils { public static String toASCII(byte b[], int start, int length) { StringBuffer asciiString = new StringBuffer(); for (int i = start; i &lt; (length + start); i++) { // exclude nulls from the ASCII representation if (b[i] != (byte) 0x00) { asciiString.append((char) b[i]); } } return asciiString.toString(); } public static String getMD5Checksum(File file) throws Exception { byte[] b = createChecksum(file); String result = ""; for (int i = 0; i &lt; b.length; i++) { result += Integer.toString((b[i] &amp; 0xff) + 0x100, 16).substring(1); } return result; } public static byte[] createChecksum(File file) throws Exception { InputStream fis = new FileInputStream(file); byte[] buffer = new byte[1024]; MessageDigest complete = MessageDigest.getInstance("MD5"); int numRead; do { numRead = fis.read(buffer); if (numRead &gt; 0) { complete.update(buffer, 0, numRead); } } while (numRead != -1); fis.close(); return complete.digest(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload