com.vrane.metaGlacierSDK.MD5File.java Source code

Java tutorial

Introduction

Here is the source code for com.vrane.metaGlacierSDK.MD5File.java

Source

/*
 * @(#)MD5File.java  0.7.0 2013 May 9
 * 
 * Copyright (c) 2013 Amherst Robots, Inc.
 * All rigts reserved.
 * 
 * See LICENSE file accompanying this file.
 */
package com.vrane.metaGlacierSDK;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * A convenient class to access md5sum of a file.
 * 
 * @author K Z Win
 */

abstract class MD5File extends File {
    private String path;
    private final static Logger LGR = Logger.getLogger(MD5File.class.getName());

    MD5File(String p) {
        super(p);
        path = p;
    }

    String md5hex() {
        try (FileInputStream in = new FileInputStream(path)) {
            return DigestUtils.md5Hex(in);
        } catch (FileNotFoundException ex) {
            LGR.log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            LGR.log(Level.SEVERE, null, ex);
        } catch (Exception e) {
            if (e.getSuppressed() != null) {
                for (Throwable t : e.getSuppressed()) {
                    LGR.log(Level.SEVERE, null, t);
                }
            } else {
                LGR.log(Level.SEVERE, null, e);
            }
        }
        return null;
    }
}