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

18
LINES

< > BotCompany Repo | #1034296 // InMemoryClassLoader - allows defining classes directly from byte arrays

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (7609L/43K).

sclass InMemoryClassLoader extends ClassLoader {
  transient settable bool rememberClassBytes;
  
  transient Map<Class, byte[]> classBytes = syncMap();
  
  *(ClassLoader parent) { super(parent); }
  
  Class<?> defineAClass(S name, byte[] bytes) {
    Class c = defineClass(name, bytes, 0, bytes.length);
    if (rememberClassBytes)
      classBytes.put(c, bytes);
    ret c;
  }
  
  byte[] getClassBytes(Class c) {
    ret classBytes.get(c);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034296
Snippet name: InMemoryClassLoader - allows defining classes directly from byte arrays
Eternal ID of this version: #1034296/4
Text MD5: 84d34bffdbc3e8727f5cc06d907c6f6e
Transpilation MD5: d8360c9c5fe379cc2e40d0528a875b29
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-29 21:10:14
Source code size: 468 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 250 / 397
Version history: 3 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)
#1035083 - LASClassLoader - class loader for classes defined in left-arrow scripts