Java Code Examples for java.io.ObjectStreamClass#forClass()

The following examples show how to use java.io.ObjectStreamClass#forClass() . 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: TestObjectStreamClass.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 2
Source File: TestObjectStreamClass.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 3
Source File: TestObjectStreamClass.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 4
Source File: TestObjectStreamClass.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 5
Source File: TestObjectStreamClass.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 6
Source File: ProxyObjectOutputStream.java    From HotswapAgent with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
    Class<?> cl = desc.forClass();
    if (ProxyFactory.isProxyClass(cl)) {
        writeBoolean(true);
        Class<?> superClass = cl.getSuperclass();
        Class<?>[] interfaces = cl.getInterfaces();
        byte[] signature = ProxyFactory.getFilterSignature(cl);
        String name = superClass.getName();
        writeObject(name);
        // we don't write the marker interface ProxyObject
        writeInt(interfaces.length - 1);
        for (int i = 0; i < interfaces.length; i++) {
            Class<?> interfaze = interfaces[i];
            if (interfaze != ProxyObject.class && interfaze != Proxy.class) {
                name = interfaces[i].getName();
                writeObject(name);
            }
        }
        writeInt(signature.length);
        write(signature);
    } else {
        writeBoolean(false);
        super.writeClassDescriptor(desc);
    }
}
 
Example 7
Source File: TestObjectStreamClass.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
    ObjectOutputStream output = new ObjectOutputStream(byteOutput);
    output.writeObject(new TestClass());

    ByteArrayInputStream bais = new ByteArrayInputStream(byteOutput.toByteArray());
    TestObjectInputStream input = new TestObjectInputStream(bais);
    input.readObject();

    ObjectStreamClass osc = input.getDescriptor();

    // All OSC public API methods should complete without throwing.
    osc.getName();
    osc.forClass();
    osc.getField("str");
    osc.getFields();
    osc.getSerialVersionUID();
    osc.toString();
}
 
Example 8
Source File: CompactedObjectOutputStream.java    From JobX with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
    Class<?> clazz = desc.forClass();
    if (clazz.isPrimitive() || clazz.isArray()) {
        write(0);
        super.writeClassDescriptor(desc);
    } else {
        write(1);
        writeUTF(desc.getName());
    }
}
 
Example 9
Source File: CompactJavaSerializer.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
SerializableDataKey(ObjectStreamClass desc, boolean store) {
  Class<?> forClass = desc.forClass();
  if (forClass != null) {
    if (store) {
      throw new AssertionError("Must not store ObjectStreamClass instances with strong references to classes");
    } else if (ObjectStreamClass.lookup(forClass) == desc) {
      this.klazz = new WeakReference<>(forClass);
    }
  }
  this.hashCode = (3 * desc.getName().hashCode()) ^ (7 * (int) (desc.getSerialVersionUID() >>> 32))
      ^ (11 * (int) desc.getSerialVersionUID());
  this.osc = desc;
}
 
Example 10
Source File: CompactedObjectOutputStream.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException
{
	Class<?> clazz = desc.forClass();
	if( clazz.isPrimitive() || clazz.isArray() )
	{
		write(0);
		super.writeClassDescriptor(desc);
	}
	else
	{
		write(1);
		writeUTF(desc.getName());
	}
}
 
Example 11
Source File: CompactedObjectOutputStream.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException
{
	Class<?> clazz = desc.forClass();
	if( clazz.isPrimitive() || clazz.isArray() )
	{
		write(0);
		super.writeClassDescriptor(desc);
	}
	else
	{
		write(1);
		writeUTF(desc.getName());
	}
}
 
Example 12
Source File: CompactObjectOutputStream.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
    Class<?> clazz = desc.forClass();
    if (clazz.isPrimitive() || clazz.isArray() || clazz.isInterface() ||
        desc.getSerialVersionUID() == 0) {
        write(TYPE_FAT_DESCRIPTOR);
        super.writeClassDescriptor(desc);
    } else {
        write(TYPE_THIN_DESCRIPTOR);
        writeUTF(desc.getName());
    }
}
 
Example 13
Source File: CompactedObjectOutputStream.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException
{
	Class<?> clazz = desc.forClass();
	if( clazz.isPrimitive() || clazz.isArray() )
	{
		write(0);
		super.writeClassDescriptor(desc);
	}
	else
	{
		write(1);
		writeUTF(desc.getName());
	}
}
 
Example 14
Source File: LocalVirtualizationOutput.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc)
		throws IOException
{
	Class<?> clazz = desc.forClass();
	if (clazz == null)
	{
		throw new RuntimeException();
	}
	
	int classIdx = virtualizationSerializer.getClassDescriptorIdx(clazz);
	writeIntCompressed(classIdx);
}
 
Example 15
Source File: CompactedObjectOutputStream.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException
{
	Class<?> clazz = desc.forClass();
	if( clazz.isPrimitive() || clazz.isArray() )
	{
		write(0);
		super.writeClassDescriptor(desc);
	}
	else
	{
		write(1);
		writeUTF(desc.getName());
	}
}
 
Example 16
Source File: CompactedObjectOutputStream.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
    Class<?> clazz = desc.forClass();
    if (clazz.isPrimitive() || clazz.isArray()) {
        write(0);
        super.writeClassDescriptor(desc);
    } else {
        write(1);
        writeUTF(desc.getName());
    }
}
 
Example 17
Source File: SerializablePortability.java    From offheap-store with Apache License 2.0 5 votes vote down vote up
public SerializableDataKey(ObjectStreamClass desc, boolean store) throws IOException {
  Class<?> forClass = desc.forClass();
  if (forClass != null) {
    if (store) {
      throw new AssertionError("Must not store ObjectStreamClass instances with strong references to classes");
    } else if (ObjectStreamClass.lookup(forClass) == desc) {
      this.klazz = new WeakReference<>(forClass);
    }
  }
  this.hashCode = (3 * desc.getName().hashCode()) ^ (7 * (int) (desc.getSerialVersionUID() >>> 32))
      ^ (11 * (int) desc.getSerialVersionUID());
  this.osc = desc;
}
 
Example 18
Source File: CompactObjectOutputStream.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
    Class<?> clazz = desc.forClass();
    if (clazz.isPrimitive() || clazz.isArray() || clazz.isInterface() ||
        desc.getSerialVersionUID() == 0) {
        write(TYPE_FAT_DESCRIPTOR);
        super.writeClassDescriptor(desc);
    } else {
        write(TYPE_THIN_DESCRIPTOR);
        writeUTF(desc.getName());
    }
}
 
Example 19
Source File: CompactedObjectOutputStream.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException
{
	Class<?> clazz = desc.forClass();
	if( clazz.isPrimitive() || clazz.isArray() )
	{
		write(0);
		super.writeClassDescriptor(desc);
	}
	else
	{
		write(1);
		writeUTF(desc.getName());
	}
}
 
Example 20
Source File: ClassFromSerializationReader.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Read the first class descriptor which indicates the serialized class, then throws a {@link ClassFoundException}
 * containing that class to avoid further reading
 */
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
	ObjectStreamClass descriptor = super.readClassDescriptor();
	throw new ClassFoundException(descriptor.forClass(), descriptor.getName());
}