import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.DigestInputStream;

class jsha384sum{
  private File myfile;

  jsha384sum(String name){
    myfile = new File(name);
  }

  public String gethash(){
    String retstr = "";
    MessageDigest md;
    FileInputStream fis = null;
    DigestInputStream dis = null;
    try{
      md = MessageDigest.getInstance("SHA-384");
      fis = new FileInputStream(myfile);
      dis = new DigestInputStream(fis, md);
      dis.on(true);
      byte buff[] = new byte[8192];
      int bp;
      while((bp = dis.read(buff)) > 0){
      }
      retstr = bytesToString(md.digest());
    }catch(NoSuchAlgorithmException e){
      retstr = "NoSuchAlgorithmException";
    }catch(FileNotFoundException e){
      retstr = "FileNotFoundException";
    }catch(IOException e){
      retstr = "IOException";
    }finally{
      try{ dis.close(); }catch(IOException e){}
      try{ fis.close(); }catch(IOException e){}
    }
    return retstr;
  }

  public String bytesToString(byte b[]){
    String hexs[] = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};

    int len = b.length;
    String str = "";
    int p, q;
    for(int i=0; i<len; i++){
      q = b[i] & 0x0f;
      p = (b[i] >> 4) & 0x0f;
      str += hexs[p] + hexs[q];
    }
    return str;
  }

  public static void main(String args[]){
    if(args.length < 1){
      System.out.println("Usage: jsha384sum filename");
      System.exit(1);
    }
    jsha384sum sha384 = new jsha384sum(args[0]);
    System.out.println(sha384.gethash());
  }
}

