use of java.io.ObjectStreamClass in project android_frameworks_base by crdroidandroid.
the class Parcel method readSerializable.
private final Serializable readSerializable(final ClassLoader loader) {
String name = readString();
if (name == null) {
// return null, which indicates that the name wasn't found in the parcel.
return null;
}
byte[] serializedData = createByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(serializedData);
try {
ObjectInputStream ois = new ObjectInputStream(bais) {
@Override
protected Class<?> resolveClass(ObjectStreamClass osClass) throws IOException, ClassNotFoundException {
// try the custom classloader if provided
if (loader != null) {
Class<?> c = Class.forName(osClass.getName(), false, loader);
if (c != null) {
return c;
}
}
return super.resolveClass(osClass);
}
};
return (Serializable) ois.readObject();
} catch (IOException ioe) {
throw new RuntimeException("Parcelable encountered " + "IOException reading a Serializable object (name = " + name + ")", ioe);
} catch (ClassNotFoundException cnfe) {
throw new RuntimeException("Parcelable encountered " + "ClassNotFoundException reading a Serializable object (name = " + name + ")", cnfe);
}
}
use of java.io.ObjectStreamClass in project camel by apache.
the class KratiDefaultSerializer method deserialize.
/**
* Deserialize an object from its raw bytes generated by {{@link #serialize(Object)}.
*
* @param binary - the raw bytes from which an object is constructed.
* @return an object constructed from the raw bytes.
* @throws SerializationException if the object cannot be constructed from the raw bytes.
*/
@SuppressWarnings("unchecked")
public T deserialize(byte[] binary) throws SerializationException {
T result = null;
ObjectInputStream ois = null;
if (binary == null) {
return null;
}
// TODO: should use Camel's ClassResolver for classloading
ByteArrayInputStream bais = new ByteArrayInputStream(binary);
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
ois = new ObjectInputStream(bais) {
@Override
public Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
try {
return classLoader.loadClass(desc.getName());
} catch (Exception e) {
}
return super.resolveClass(desc);
}
};
result = (T) ois.readObject();
} catch (IOException e) {
LOG.warn("Error while deserializing object. Null will be used.", e);
} catch (ClassNotFoundException e) {
LOG.warn("Could not find class while deserializing object. Null will be used.", e);
} finally {
IOHelper.close(ois, bais);
}
return result;
}
use of java.io.ObjectStreamClass in project WorldPainter by Captain-Chaos.
the class WPCustomObjectInputStream method readClassDescriptor.
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
ObjectStreamClass resultClassDescriptor = super.readClassDescriptor();
Class localClass = resolveClass(resultClassDescriptor);
if (patchClasses.contains(localClass)) {
ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
if (localClassDescriptor != null) {
final long localSUID = localClassDescriptor.getSerialVersionUID();
final long streamSUID = resultClassDescriptor.getSerialVersionUID();
if (streamSUID != localSUID) {
logger.warn("Overriding serialized class version mismatch: local serialVersionUID = " + localSUID + " stream serialVersionUID = " + streamSUID);
resultClassDescriptor = localClassDescriptor;
}
}
} else if (localClass == null) {
logger.warn("No local class for " + resultClassDescriptor.getName());
}
return resultClassDescriptor;
}
use of java.io.ObjectStreamClass in project fabric8 by jboss-fuse.
the class ZkDataStoreImpl method getContainerMetadata.
@Override
public CreateContainerMetadata getContainerMetadata(String containerId, final ClassLoader classLoader) {
assertValid();
try {
byte[] encoded = getByteData(configCache, ZkPath.CONTAINER_METADATA.getPath(containerId));
if (encoded == null) {
return null;
}
byte[] decoded = Base64Encoder.decode(encoded);
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(decoded)) {
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
return classLoader.loadClass(desc.getName());
}
};
return (CreateContainerMetadata) ois.readObject();
} catch (ClassNotFoundException | InvalidClassException | KeeperException.NoNodeException e) {
return null;
} catch (Exception e) {
throw FabricException.launderThrowable(e);
}
}
use of java.io.ObjectStreamClass in project revapi by revapi.
the class SUIDGeneratorTest method testSUIDGeneration.
@Test
public void testSUIDGeneration() throws Exception {
try {
ObjectStreamClass s = ObjectStreamClass.lookup(TestClass.class);
long officialSUID = s.getSerialVersionUID();
SUIDGeneratingAnnotationProcessor ap = new SUIDGeneratingAnnotationProcessor();
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, null, Arrays.asList(TestClass.class.getName()), Arrays.asList(new SourceInClassLoader("suid/TestClass.java")));
task.setProcessors(Arrays.asList(ap));
task.call();
Assert.assertEquals(officialSUID, ap.generatedSUID);
} finally {
new File("TestClass.class").delete();
}
}
Aggregations