Java Code Examples for java.io.ObjectStreamClass#lookupAny()
The following examples show how to use
java.io.ObjectStreamClass#lookupAny() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompactObjectInputStream.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { int type = read(); if (type < 0) { throw new EOFException(); } switch (type) { case CompactObjectOutputStream.TYPE_FAT_DESCRIPTOR: return super.readClassDescriptor(); case CompactObjectOutputStream.TYPE_THIN_DESCRIPTOR: String className = readUTF(); Class<?> clazz = classResolver.resolve(className); return ObjectStreamClass.lookupAny(clazz); default: throw new StreamCorruptedException( "Unexpected class descriptor type: " + type); } }
Example 2
Source File: ObjectInputStreamProxyTest.java From gadtry with Apache License 2.0 | 6 votes |
@Test public void resolveClass() throws IOException, ClassNotFoundException { ObjectStreamClass intClass = ObjectStreamClass.lookupAny(int.class); byte[] bytes = Serializables.serialize(1); ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(bytes); ObjectInputStreamProxy objectInputStream = new ObjectInputStreamProxy(arrayInputStream, ObjectInputStreamProxy.getLatestUserDefinedLoader()); when(objectStreamClass.getName()).thenReturn("gadtry.gadtry.gadtry.gadtry"); Assert.assertEquals(int.class, objectInputStream.resolveClass(intClass)); try { objectInputStream.resolveClass(objectStreamClass); Assert.fail(); } catch (ClassNotFoundException ignored) { } //ObjectStreamClass Assert.assertEquals(1, (int) objectInputStream.readObject()); }
Example 3
Source File: CompactObjectInputStream.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { int type = read(); if (type < 0) { throw new EOFException(); } switch (type) { case CompactObjectOutputStream.TYPE_FAT_DESCRIPTOR: return super.readClassDescriptor(); case CompactObjectOutputStream.TYPE_THIN_DESCRIPTOR: String className = readUTF(); Class<?> clazz = classResolver.resolve(className); return ObjectStreamClass.lookupAny(clazz); default: throw new StreamCorruptedException( "Unexpected class descriptor type: " + type); } }
Example 4
Source File: ObjectStreamClassTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.io.ObjectStreamClass#lookupAny(java.lang.Class) * @since 1.6 */ public void test_lookupAnyLjava_lang_Class() { // Test for method java.io.ObjectStreamClass // java.io.ObjectStreamClass.lookupAny(java.lang.Class) ObjectStreamClass osc = ObjectStreamClass.lookupAny(DummyClass.class); assertEquals("lookup returned wrong class: " + osc.getName(), "org.apache.harmony.tests.java.io.ObjectStreamClassTest$DummyClass", osc .getName()); osc = ObjectStreamClass.lookupAny(NonSerialzableClass.class); assertEquals("lookup returned wrong class: " + osc.getName(), "org.apache.harmony.tests.java.io.ObjectStreamClassTest$NonSerialzableClass", osc.getName()); osc = ObjectStreamClass.lookupAny(ExternalizableClass.class); assertEquals("lookup returned wrong class: " + osc.getName(), "org.apache.harmony.tests.java.io.ObjectStreamClassTest$ExternalizableClass", osc.getName()); osc = ObjectStreamClass.lookup(NonSerialzableClass.class); assertNull(osc); }
Example 5
Source File: SerializableDemo.java From Learn-Java-12-Programming with MIT License | 5 votes |
public static void main(String... args) { ObjectStreamClass osc1 = ObjectStreamClass.lookup(Person1.class); printInfo(osc1); ObjectStreamClass osc2 = ObjectStreamClass.lookup(Person2.class); System.out.println("osc2: " + osc2); ObjectStreamClass osc3 = ObjectStreamClass.lookupAny(Person2.class); printInfo(osc3); }
Example 6
Source File: LocalVirtualizationInput.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException { int classIdx = readIntCompressed(); Class<?> clazz = serializer.getClassForDescriptorIdx(classIdx); ObjectStreamClass descriptor = ObjectStreamClass.lookupAny(clazz); return descriptor; }
Example 7
Source File: SerializationTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testArraySerialVersionUIDs() throws Exception { ObjectStreamClass osc = ObjectStreamClass.lookupAny(new int[0].getClass()); assertEquals(5600894804908749477L, osc.getSerialVersionUID()); osc = ObjectStreamClass.lookupAny(new int[0][0].getClass()); assertEquals(1727100010502261052L, osc.getSerialVersionUID()); osc = ObjectStreamClass.lookupAny(new double[0].getClass()); assertEquals(4514449696888150558L, osc.getSerialVersionUID()); osc = ObjectStreamClass.lookupAny(new String[0].getClass()); assertEquals(-5921575005990323385L, osc.getSerialVersionUID()); osc = ObjectStreamClass.lookupAny(new Thread[0].getClass()); assertEquals(-6192713741133905679L, osc.getSerialVersionUID()); }
Example 8
Source File: Jdk6ClassLookup.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public ObjectStreamClass transform(Class<?> original) { return ObjectStreamClass.lookupAny(original); }
Example 9
Source File: Jdk6ClassLookup.java From pushfish-android with BSD 2-Clause "Simplified" License | 4 votes |
public ObjectStreamClass transform(Class<?> original) { return ObjectStreamClass.lookupAny(original); }
Example 10
Source File: Jdk6ClassLookup.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public ObjectStreamClass transform(Class<?> original) { return ObjectStreamClass.lookupAny(original); }
Example 11
Source File: Jdk6ClassLookup.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 4 votes |
public ObjectStreamClass transform(Class<?> original) { return ObjectStreamClass.lookupAny(original); }