-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df1e5d2
commit db7ba74
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/org/nustaq/serialization/serializers/FSTProxySerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.nustaq.serialization.serializers; | ||
|
||
|
||
import org.nustaq.serialization.FSTBasicObjectSerializer; | ||
import org.nustaq.serialization.FSTClazzInfo; | ||
import org.nustaq.serialization.FSTObjectInput; | ||
import org.nustaq.serialization.FSTObjectOutput; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Proxy; | ||
|
||
|
||
public class FSTProxySerializer extends FSTBasicObjectSerializer { | ||
|
||
@Override | ||
public void writeObject(FSTObjectOutput out, Object toWrite, FSTClazzInfo clzInfo, FSTClazzInfo.FSTFieldInfo referencedBy, int streamPosition) throws IOException { | ||
Class<?>[] ifaces = clzInfo.getClazz().getInterfaces(); | ||
ClassLoader cl = out.getConf().getClassLoader(); | ||
out.writeInt(ifaces.length); | ||
for (Class i : ifaces) | ||
out.writeUTF(i.getName()); | ||
out.writeObject(Proxy.getInvocationHandler(toWrite)); | ||
} | ||
|
||
@Override | ||
public Object instantiate(Class objectClass, FSTObjectInput in, FSTClazzInfo serializationInfo, FSTClazzInfo.FSTFieldInfo referencee, int streamPositioin) throws IOException, ClassNotFoundException { | ||
ClassLoader cl = in.getConf().getClassLoader(); | ||
int numIfaces = in.readInt(); | ||
String[] interfaces = new String[numIfaces]; | ||
for (int i = 0; i < numIfaces; i++) { | ||
interfaces[i] = in.readUTF(); | ||
} | ||
Class[] classObjs = new Class[interfaces.length]; | ||
|
||
for(int i = 0; i < interfaces.length; ++i) { | ||
try { | ||
classObjs[i] = Class.forName(interfaces[i], false, cl); | ||
} catch (ClassNotFoundException e) { | ||
classObjs[i] = Class.forName(interfaces[i], false, this.getClass().getClassLoader()); | ||
} | ||
} | ||
InvocationHandler ih = (InvocationHandler)in.readObject(); | ||
Object res = Proxy.newProxyInstance(in.getConf().getClassLoader(),classObjs,ih); | ||
in.registerObject(res,streamPositioin,serializationInfo,referencee); | ||
return res; | ||
} | ||
} |
db7ba74
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see #231 (comment)