This commit is contained in:
地平线
2015-10-28 16:22:32 +08:00
parent 99ac18b156
commit 9399065346

View File

@@ -32,6 +32,10 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
protected Factory factory;
private boolean inited = false;
private final Object lock = new Object();
protected ObjectDecoder(Type type) {
this.type = ((type instanceof Class) && ((Class) type).isInterface()) ? Object.class : type;
if (type instanceof ParameterizedType) {
@@ -45,6 +49,7 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
public void init(final Factory factory) {
this.factory = factory;
try {
if (type == Object.class) return;
Class clazz = null;
@@ -96,6 +101,12 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
} catch (Exception ex) {
throw new ConvertException(ex);
}
} finally {
inited = true;
synchronized (lock) {
lock.notifyAll();
}
}
}
/**
@@ -109,6 +120,16 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
final String clazz = in.readClassName();
if (clazz != null && !clazz.isEmpty()) return (T) factory.loadDecoder(factory.getEntity(clazz)).convertFrom(in);
if (in.readObjectB() == Reader.SIGN_NULL) return null;
if (!this.inited) {
synchronized (lock) {
try {
lock.wait();
} catch (Exception e) {
e.printStackTrace();
}
}
}
final T result = this.creator.create();
final AtomicInteger index = new AtomicInteger();
while (in.hasNext()) {