本文整理汇总了Java中java.io.Externalizable类的典型用法代码示例。如果您正苦于以下问题:Java Externalizable类的具体用法?Java Externalizable怎么用?Java Externalizable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Externalizable类属于java.io包,在下文中一共展示了Externalizable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCommandObject
import java.io.Externalizable; //导入依赖的package包/类
/**
* Returns the instantiated bean.
* If the bean implements <code>CommandObject</code>, its
* <code>setCommandContext</code> method will be called.
* @param dh the data handler describing the command data
* @param loader the class loader used to instantiate the bean
*/
public Object getCommandObject(DataHandler dh, ClassLoader loader)
throws IOException, ClassNotFoundException
{
Object object = Beans.instantiate(loader, className);
if (object != null)
{
if (object instanceof CommandObject)
{
CommandObject command = (CommandObject)object;
command.setCommandContext(verb, dh);
}
else if (dh != null && (object instanceof Externalizable))
{
InputStream in = dh.getInputStream();
if (in != null)
{
Externalizable externalizable = (Externalizable)object;
externalizable.readExternal(new ObjectInputStream(in));
}
}
}
return object;
}
示例2: testSortedSetWithNaturalOrderingOnRefs
import java.io.Externalizable; //导入依赖的package包/类
public void testSortedSetWithNaturalOrderingOnRefs() throws Exception {
Object factoryBean = appContext.getBean("&sortedSetWithNaturalOrderingOnRefs");
assertTrue(factoryBean instanceof OsgiServiceCollectionProxyFactoryBean);
Comparator comp = getComparator(factoryBean);
assertNotNull(comp);
assertSame(ServiceReferenceComparator.class, comp.getClass());
Class<?>[] intfs = getInterfaces(factoryBean);
assertTrue(Arrays.equals(new Class<?>[] { Externalizable.class }, intfs));
OsgiServiceLifecycleListener[] listeners = getListeners(factoryBean);
assertEquals(2, listeners.length);
Object bean = appContext.getBean("sortedSetWithNaturalOrderingOnRefs");
assertFalse(bean instanceof OsgiServiceSortedSet);
assertTrue(bean instanceof SortedSet);
}
示例3: toCompressedBytes
import java.io.Externalizable; //导入依赖的package包/类
public static byte[] toCompressedBytes(@Nonnull final Externalizable obj,
@Nonnull final CompressionAlgorithm algo, final boolean bin2txt) throws IOException {
FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream();
OutputStream out = null;
FinishableOutputStream dos = null;
try {
out = bin2txt ? new Base91OutputStream(bos) : bos;
dos = CompressionStreamFactory.createOutputStream(out, algo);
toStream(obj, dos);
dos.finish();
//dos.flush();
return bos.toByteArray_clear();
} finally {
IOUtils.closeQuietly(dos);
IOUtils.closeQuietly(out);
}
}
示例4: onTransact
import java.io.Externalizable; //导入依赖的package包/类
@Override
protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
switch(code) {
case TRANSACT_methodReturningTheExternalizable: {
data.enforceInterface(this.getInterfaceDescriptor());
final Externalizable returnValue = delegate.methodReturningTheExternalizable();
reply.writeNoException();
AidlUtil.writeToObjectStream(reply, returnValue);
return true;
}
}
return super.onTransact(code, data, reply, flags);
}
示例5: methodReturningTheExternalizable
import java.io.Externalizable; //导入依赖的package包/类
@Override
public Externalizable methodReturningTheExternalizable() throws RemoteException {
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
try {
data.writeInterfaceToken(ExternalizableTest3$$AidlServerImpl.DESCRIPTOR);
delegate.transact(ExternalizableTest3$$AidlServerImpl.TRANSACT_methodReturningTheExternalizable, data, reply, 0);
reply.readException();
return AidlUtil.readFromObjectStream(reply);
} finally {
data.recycle();
reply.recycle();
}
}
示例6: deSerialize
import java.io.Externalizable; //导入依赖的package包/类
public static Graph deSerialize(byte[] byteArray,
Class<? extends Externalizable> clazz) {
ObjectInputStream ois;
Graph graph;
try {
ois = new ObjectInputStream(new ByteArrayInputStream(byteArray));
graph = (Graph) clazz.newInstance();
graph.readExternal(ois);
ois.close();
} catch (IOException | ClassNotFoundException | InstantiationException
| IllegalAccessException e) {
e.printStackTrace();
return null;
}
Preconditions.checkNotNull(graph);
return graph;
}
示例7: isCustomJavaSerialization
import java.io.Externalizable; //导入依赖的package包/类
/**
* Determines whether class contains custom Java serialization logic.
*
* @param cls Class.
* @return {@code true} if custom Java serialization logic exists, {@code false} otherwise.
*/
@SuppressWarnings("unchecked")
public static boolean isCustomJavaSerialization(Class cls) {
for (Class c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
if (Externalizable.class.isAssignableFrom(c))
return true;
try {
Method writeObj = c.getDeclaredMethod("writeObject", ObjectOutputStream.class);
Method readObj = c.getDeclaredMethod("readObject", ObjectInputStream.class);
if (!Modifier.isStatic(writeObj.getModifiers()) && !Modifier.isStatic(readObj.getModifiers()) &&
writeObj.getReturnType() == void.class && readObj.getReturnType() == void.class)
return true;
}
catch (NoSuchMethodException ignored) {
// No-op.
}
}
return false;
}
示例8: readExternalizable
import java.io.Externalizable; //导入依赖的package包/类
/**
*
*/
protected void readExternalizable(String className, Object object) throws ClassNotFoundException, IOException
{
if (object instanceof Externalizable)
{
if (isDebug)
trace.startExternalizableObject(className, objectTable.size() - 1);
((Externalizable)object).readExternal(this);
}
else
{
//Class '{className}' must implement java.io.Externalizable to receive client IExternalizable instances.
SerializationException ex = new SerializationException();
ex.setMessage(10305, new Object[] {object.getClass().getName()});
throw ex;
}
}
示例9: deserialize
import java.io.Externalizable; //导入依赖的package包/类
@SneakyThrows
public Object deserialize(AmfReader reader) {
Object result = cls.newInstance();
if (result instanceof Externalizable) {
((Externalizable) result).readExternal(reader);
return result;
}
for (Map.Entry<String, Object> field : reader.readAmf0KeyValuePairs().entrySet()) {
setField(result, field.getKey(), field.getValue());
}
return result;
}
示例10: testSortedSetWithNaturalOrderingOnRefs
import java.io.Externalizable; //导入依赖的package包/类
public void testSortedSetWithNaturalOrderingOnRefs() throws Exception {
Object factoryBean = appContext.getBean("&sortedSetWithNaturalOrderingOnRefs");
assertTrue(factoryBean instanceof OsgiServiceCollectionProxyFactoryBean);
Comparator comp = getComparator(factoryBean);
assertNotNull(comp);
assertSame(ServiceReferenceComparator.class, comp.getClass());
Class[] intfs = getInterfaces(factoryBean);
assertTrue(Arrays.equals(new Class[] { Externalizable.class }, intfs));
OsgiServiceLifecycleListener[] listeners = getListeners(factoryBean);
assertEquals(2, listeners.length);
Object bean = appContext.getBean("sortedSetWithNaturalOrderingOnRefs");
assertFalse(bean instanceof OsgiServiceSortedSet);
assertTrue(bean instanceof SortedSet);
}
示例11: instantiateAndReadNoSer
import java.io.Externalizable; //导入依赖的package包/类
protected Object instantiateAndReadNoSer(Class c, FSTClazzInfo clzSerInfo, FSTClazzInfo.FSTFieldInfo referencee, int readPos) throws Exception {
Object newObj;
newObj = clzSerInfo.newInstance(getCodec().isMapBased());
if (newObj == null) {
throw new IOException(referencee.getDesc() + ":Failed to instantiate '" + c.getName() + "'. Register a custom serializer implementing instantiate or define empty constructor..");
}
if ( clzSerInfo.isExternalizable() )
{
getCodec().ensureReadAhead(readExternalReadAHead);
((Externalizable)newObj).readExternal(this);
getCodec().readExternalEnd();
} else {
FSTClazzInfo.FSTFieldInfo[] fieldInfo = clzSerInfo.getFieldInfo();
readObjectFields(referencee, clzSerInfo, fieldInfo, newObj,0,0);
}
return newObj;
}
示例12: writeNullableObject
import java.io.Externalizable; //导入依赖的package包/类
public static void writeNullableObject(Serializable object, ObjectOutput out) throws IOException
{
boolean isNull = object == null;
out.writeBoolean(isNull);
if( !isNull )
{
if( object instanceof Externalizable )
{
((Externalizable)object).writeExternal(out);
}
else
{
out.writeObject(object);
}
}
}
示例13: serializeToBytes
import java.io.Externalizable; //导入依赖的package包/类
public static byte[] serializeToBytes(Externalizable e) throws IOException {
ByteArrayOutputStream bos = null;
ObjectOutputStream oos = null;
byte[] object;
try{
bos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bos);
oos.writeObject(e);
oos.flush();
object = bos.toByteArray();
} finally {
if(oos != null){
oos.close();
}
if(bos != null){
bos.close();
}
}
return object;
}
示例14: testGet
import java.io.Externalizable; //导入依赖的package包/类
@Test
public void testGet() {
InterfaceMap<Object> map = new InterfaceMap<Object>();
A a = new A();
B b = new B();
map.put(a, a);
map.put(b, b);
assertSame(a, map.get(Runnable.class));
assertSame(b, map.get(Externalizable.class));
assertSame(b, map.get(Comparable.class));
}
示例15: isExcplicitlyRequiredClass
import java.io.Externalizable; //导入依赖的package包/类
private boolean isExcplicitlyRequiredClass(Class<?> i) {
Set<Class<?>> requiredClasses = new HashSet<Class<?>>();
requiredClasses.add(EJBTestBase.Caller.class);
requiredClasses.add(Comparable.class);
requiredClasses.add(Runnable.class);
requiredClasses.add(Externalizable.class);
requiredClasses.add(javax.enterprise.event.Event.class);
requiredClasses.add(org.slf4j.Logger.class);
return requiredClasses.contains(i);
}