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: 283 / 347
Version history: 3 change(s)
Referenced in: [show references]