Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.FileOutputStream;

import java.io.IOException;
import java.io.InputStream;

import java.security.MessageDigest;

import android.util.Log;

public class Main {
    private static final String TAG = "NarUtil";

    public static byte[] copyFile(InputStream is, FileOutputStream os) throws IOException {
        MessageDigest digester = null;
        try {
            digester = MessageDigest.getInstance("MD5");

            byte[] buffer = new byte[16 * 1024];
            int length;
            while ((length = is.read(buffer)) > 0) {
                os.write(buffer, 0, length);
                digester.update(buffer, 0, length);
            }
            os.flush();
            os.close();

            //os.getFD().sync();
            //Log.d(TAG, "done copying");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            is.close();
            Log.d(TAG, "done copying");
        }
        if (digester != null) {
            byte[] digest = digester.digest();
            return digest;
        }

        return null;
    }
}