Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

25
LINES

< > BotCompany Repo | #1016251 // md5OfFile

JavaX fragment (include)

sbool md5OfFile_verbose;

static S md5OfFile(S path) {
  ret md5OfFile(newFile(path));
}

static S md5OfFile(File f) ctex {
  if (!f.exists()) ret "-";
  
  if (md5OfFile_verbose)
    print("Getting MD5 of " + f);
  
  MessageDigest md5 = MessageDigest.getInstance("MD5");
  temp FileInputStream in = new FileInputStream(f);

  byte buf[] = new byte[65536];
  int l;
  while (true) {
    l = in.read(buf);
    if (l <= 0) break;
    md5.update(buf, 0, l);
  }
  
  ret bytesToHex(md5.digest());
}

Author comment

Began life as a copy of #1000998

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney

No comments. add comment

Snippet ID: #1016251
Snippet name: md5OfFile
Eternal ID of this version: #1016251/4
Text MD5: 37fa3d5071937a26d94cc37946b2bf8c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-28 14:15:06
Source code size: 520 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 342 / 407
Version history: 3 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1019889 - md5OfFile_throughString - go through UTF8 conversion
#1027114 - md5_finish
#1034044 - md5OfStream
#1035806 - md5OfFileAsByteArray