закладки  1

  •  

    Create a ObjectOutputStream that overrides writeClassDescriptor and stores the classloader name also: public class TestCLOutputStream extends ObjectOutputStream { TestCLOutputStream(OutputStream str) throws IOException { super(str); } @Override protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException { super.writeClassDescriptor(desc); //Write the classloader name String ldr = desc.forClass().getClassLoader().toString(); writeObject(ldr); } } Create a ObjectInputStream that overrides the readClassDescriptor: public class TestCLInputStream extends ObjectInputStream { private Map _loaders; TestCLInputStream(InputStream str) throws IOException { super(str); _loaders = new HashMap(); } @Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { ObjectStreamClass cls = super.readClassDescriptor(); String ldr = (String)readObject(); _loaders.put(cls, ldr); return cls; } protected ClassresolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { //use look up functionality to ClassLoader ldr = _loader.get(_loaders.get(desc)); if (ldr != null) return ldr.loadClass(desc.getName()); return super.resolveClass(desc); } }
    5 лет назад , @jil
    (0)
     
     
  • ⟨⟨
  • 1
  • ⟩
  • ⟩⟩

публикации  

    Нет подходящих.
  • ⟨⟨
  • ⟩
  • ⟩⟩