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

The following examples show how to use java.io.ObjectStreamClass#forClass() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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
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
@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 4
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
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
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 7
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
@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
@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 10
Source Project: ehcache3   File: CompactJavaSerializer.java    License: 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 11
@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
@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 13
@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
@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 15
@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 16
@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
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
@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
@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
/**
 * 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());
}