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

24
LINES

< > BotCompany Repo | #1018925 // classSizeInBytes

JavaX fragment (include)

1  
static Map<Class, Int> classSizeInBytes_cache = weakHashMap();
2  
3  
static int classSizeInBytes(Class c) {
4  
  Int size = classSizeInBytes_cache.get(c);
5  
  if (size == null)
6  
    classSizeInBytes_cache.put(c, size = classSizeInBytes_uncached(c));
7  
  ret size;
8  
}
9  
10  
static int classSizeInBytes_uncached(Class c) ctex {
11  
  L<File> files = cast get(getClassLoader(c), 'files);
12  
  S name = c.getName().replace('.', '/') + ".class";
13  
  for (File location : files) 
14  
    if (location.isDirectory()) {
15  
      File f = new File(location, name);
16  
      if (f.exists()) ret toInt_checked(fileSize(f));
17  
    } else if (location.isFile()) pcall {
18  
      temp ZipFile zip = new ZipFile(location);
19  
      ZipEntry entry = zip.getEntry(name);
20  
      if (entry != null) ret toInt_checked(entry.getSize());
21  
    }
22  
  print(name + " not found in: " + files);
23  
  ret -1;
24  
}

Author comment

Began life as a copy of #1012231

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1018925
Snippet name: classSizeInBytes
Eternal ID of this version: #1018925/10
Text MD5: 4782674025da33b3b3b82f40419a145d
Author: stefan
Category: javax / byte code
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-16 01:58:47
Source code size: 852 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 384 / 425
Version history: 9 change(s)
Referenced in: [show references]