优化LambdaFunction
This commit is contained in:
@@ -300,21 +300,12 @@ public final class Utility {
|
|||||||
|
|
||||||
private static String readLambdaFieldNameFromBytes(Serializable func) {
|
private static String readLambdaFieldNameFromBytes(Serializable func) {
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ObjectWriteStream out = new ObjectWriteStream();
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(out);
|
out.enableReplaceObject(true);
|
||||||
oos.writeObject(func);
|
out.writeObject(func);
|
||||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray())) {
|
out.close();
|
||||||
@Override
|
return readFieldName(out.methodNameReference.get());
|
||||||
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
|
} catch (IOException e) {
|
||||||
if (desc.getName().contains("SerializedLambda") || desc.getName().contains("$Lambda$")) {
|
|
||||||
return org.redkale.util.SerializedLambda.class;
|
|
||||||
} else {
|
|
||||||
return super.resolveClass(desc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return Utility.readFieldName(((org.redkale.util.SerializedLambda) in.readObject()).getImplMethodName());
|
|
||||||
} catch (Throwable e) {
|
|
||||||
throw new RedkaleException(e);
|
throw new RedkaleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -337,6 +328,28 @@ public final class Utility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class ObjectWriteStream extends ObjectOutputStream {
|
||||||
|
|
||||||
|
public final ObjectReference<String> methodNameReference = new ObjectReference<>();
|
||||||
|
|
||||||
|
public ObjectWriteStream() throws IOException {
|
||||||
|
super(new ByteArrayOutputStream());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object replaceObject(Object obj) throws IOException {
|
||||||
|
if (obj instanceof java.lang.invoke.SerializedLambda) {
|
||||||
|
methodNameReference.set(((java.lang.invoke.SerializedLambda) obj).getImplMethodName());
|
||||||
|
}
|
||||||
|
return super.replaceObject(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enableReplaceObject(boolean enable) throws SecurityException {
|
||||||
|
return super.enableReplaceObject(enable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param value from which next positive power of two will be found.
|
* @param value from which next positive power of two will be found.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user