java.io.ObjectStreamClass#forClass ( )源码实例Demo

下面列出了java.io.ObjectStreamClass#forClass ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: TestObjectStreamClass.java
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();
}
 
源代码2 项目: TencentKona-8   文件: TestObjectStreamClass.java
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();
}
 
源代码3 项目: HotswapAgent   文件: ProxyObjectOutputStream.java
@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);
    }
}
 
源代码4 项目: openjdk-jdk9   文件: TestObjectStreamClass.java
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();
}
 
源代码5 项目: jdk8u-jdk   文件: TestObjectStreamClass.java
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();
}
 
源代码6 项目: hottub   文件: TestObjectStreamClass.java
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();
}
 
源代码7 项目: jdk8u_jdk   文件: TestObjectStreamClass.java
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();
}
 
源代码8 项目: dubbo-2.6.5   文件: CompactedObjectOutputStream.java
@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());
    }
}
 
源代码9 项目: netty-4.1.22   文件: CompactObjectOutputStream.java
@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());
    }
}
 
源代码10 项目: ehcache3   文件: CompactJavaSerializer.java
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;
}
 
源代码11 项目: JobX   文件: CompactedObjectOutputStream.java
@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());
    }
}
 
源代码12 项目: dubbox   文件: CompactedObjectOutputStream.java
@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());
	}
}
 
@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());
	}
}
 
源代码14 项目: dubbo3   文件: CompactedObjectOutputStream.java
@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());
	}
}
 
源代码15 项目: jasperreports   文件: LocalVirtualizationOutput.java
@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);
}
 
源代码16 项目: dubbox   文件: CompactedObjectOutputStream.java
@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());
	}
}
 
源代码17 项目: offheap-store   文件: SerializablePortability.java
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;
}
 
@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());
    }
}
 
源代码19 项目: dubbox   文件: CompactedObjectOutputStream.java
@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());
	}
}
 
/**
 * 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());
}