Java Code Examples for java.io.ObjectStreamClass.lookup()

The following are Jave code examples for showing how to use lookup() of the java.io.ObjectStreamClass class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: EatDubbo   File: CompactedObjectInputStream.java   View Source Code Vote up 6 votes
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException,ClassNotFoundException
{
	int type = read();
	if( type < 0 )
		throw new EOFException();
	switch( type )
	{
		case 0:
			return super.readClassDescriptor();
		case 1:
			Class<?> clazz = loadClass(readUTF());
			return ObjectStreamClass.lookup(clazz);
		default:
			throw new StreamCorruptedException("Unexpected class descriptor type: " + type);
	}
}
 
Example 2
Project: ooso   File: DecompressibleInputStream.java   View Source Code Vote up 6 votes
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
    ObjectStreamClass resultClassDescriptor = super.readClassDescriptor();
    Class localClass;
    try {
        localClass = Class.forName(resultClassDescriptor.getName());
    } catch (ClassNotFoundException e) {
        return resultClassDescriptor;
    }
    ObjectStreamClass localClassDescriptor = ObjectStreamClass.lookup(localClass);
    if (localClassDescriptor != null) {
        final long localSUID = localClassDescriptor.getSerialVersionUID();
        final long streamSUID = resultClassDescriptor.getSerialVersionUID();
        if (streamSUID != localSUID) {
            resultClassDescriptor = localClassDescriptor;
        }
    }
    return resultClassDescriptor;
}
 
Example 3
Project: dubbo2   File: CompactedObjectInputStream.java   View Source Code Vote up 6 votes
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException,ClassNotFoundException
{
	int type = read();
	if( type < 0 )
		throw new EOFException();
	switch( type )
	{
		case 0:
			return super.readClassDescriptor();
		case 1:
			Class<?> clazz = loadClass(readUTF());
			return ObjectStreamClass.lookup(clazz);
		default:
			throw new StreamCorruptedException("Unexpected class descriptor type: " + type);
	}
}
 
Example 4
Project: OpenJSharp   File: ValueType.java   View Source Code Vote up 6 votes
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
 
Example 5
Project: dubbox-hystrix   File: CompactedObjectInputStream.java   View Source Code Vote up 6 votes
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException,ClassNotFoundException
{
	int type = read();
	if( type < 0 )
		throw new EOFException();
	switch( type )
	{
		case 0:
			return super.readClassDescriptor();
		case 1:
			Class<?> clazz = loadClass(readUTF());
			return ObjectStreamClass.lookup(clazz);
		default:
			throw new StreamCorruptedException("Unexpected class descriptor type: " + type);
	}
}
 
Example 6
Project: jdk8u-jdk   File: ClassDesc.java   View Source Code Vote up 6 votes
/**
 * Write and read class descriptors to/from a stream.
 * Arguments: <# cycles>
 */
public long run(String[] args) throws Exception {
    int ncycles = Integer.parseInt(args[0]);
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());
    ObjectStreamClass desc = ObjectStreamClass.lookup(Dummy50.class);

    doReps(oout, oin, sbuf, desc, 1);       // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, desc, ncycles);
    return System.currentTimeMillis() - start;
}
 
Example 7
Project: jdk8u-jdk   File: ProxyClassDesc.java   View Source Code Vote up 6 votes
/**
 * Generate proxy class descriptors.
 */
ObjectStreamClass[] genDescs() {
    ClassLoader ldr = ProxyClassDesc.class.getClassLoader();
    Class[] ifaces = new Class[3];
    Class[] a =
        new Class[] { A1.class, A2.class, A3.class, A4.class, A5.class };
    Class[] b =
        new Class[] { B1.class, B2.class, B3.class, B4.class, B5.class };
    Class[] c =
        new Class[] { C1.class, C2.class, C3.class, C4.class, C5.class };
    ObjectStreamClass[] descs =
        new ObjectStreamClass[a.length * b.length * c.length];
    int n = 0;
    for (int i = 0; i < a.length; i++) {
        ifaces[0] = a[i];
        for (int j = 0; j < b.length; j++) {
            ifaces[1] = b[j];
            for (int k = 0; k < c.length; k++) {
                ifaces[2] = c[k];
                Class proxyClass = Proxy.getProxyClass(ldr, ifaces);
                descs[n++] = ObjectStreamClass.lookup(proxyClass);
            }
        }
    }
    return descs;
}
 
Example 8
Project: openjdk-jdk10   File: ValueType.java   View Source Code Vote up 6 votes
/**
 * Get the names and types of all the persistent fields of a Class.
 */
private Hashtable getPersistentFields (Class clz) {
    Hashtable result = new Hashtable();
    ObjectStreamClass osc = ObjectStreamClass.lookup(clz);
    if (osc != null) {
        ObjectStreamField[] fields = osc.getFields();
        for (int i = 0; i < fields.length; i++) {
            String typeSig;
            String typePrefix = String.valueOf(fields[i].getTypeCode());
            if (fields[i].isPrimitive()) {
                typeSig = typePrefix;
            } else {
                if (fields[i].getTypeCode() == '[') {
                    typePrefix = "";
                }
                typeSig = typePrefix + fields[i].getType().getName().replace('.','/');
                if (typeSig.endsWith(";")) {
                    typeSig = typeSig.substring(0,typeSig.length()-1);
                }
            }
            result.put(fields[i].getName(),typeSig);
        }
    }
    return result;
}
 
Example 9
Project: openjdk-jdk10   File: ClassDesc.java   View Source Code Vote up 6 votes
/**
 * Write and read class descriptors to/from a stream.
 * Arguments: <# cycles>
 */
public long run(String[] args) throws Exception {
    int ncycles = Integer.parseInt(args[0]);
    StreamBuffer sbuf = new StreamBuffer();
    ObjectOutputStream oout =
        new ObjectOutputStream(sbuf.getOutputStream());
    ObjectInputStream oin =
        new ObjectInputStream(sbuf.getInputStream());
    ObjectStreamClass desc = ObjectStreamClass.lookup(Dummy50.class);

    doReps(oout, oin, sbuf, desc, 1);       // warmup

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, desc, ncycles);
    return System.currentTimeMillis() - start;
}
 
Example 10
Project: dubbocloud   File: CompactedObjectInputStream.java   View Source Code Vote up 6 votes
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException,ClassNotFoundException
{
	int type = read();
	if( type < 0 )
		throw new EOFException();
	switch( type )
	{
		case 0:
			return super.readClassDescriptor();
		case 1:
			Class<?> clazz = loadClass(readUTF());
			return ObjectStreamClass.lookup(clazz);
		default:
			throw new StreamCorruptedException("Unexpected class descriptor type: " + type);
	}
}
 
Example 11
Project: Squid   File: Average.java   View Source Code Vote up 5 votes
private void readObject(
        ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    ObjectStreamClass myObject = ObjectStreamClass.lookup(Class.forName(Average.class.getCanonicalName()));
    long theSUID = myObject.getSerialVersionUID();
    System.out.println("Customized De-serialization of Average " + theSUID);
}
 
Example 12
Project: Squid   File: Exp.java   View Source Code Vote up 5 votes
private void readObject(
        ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    ObjectStreamClass myObject = ObjectStreamClass.lookup(Class.forName(Exp.class.getCanonicalName()));
    long theSUID = myObject.getSerialVersionUID();
    System.out.println("Customized De-serialization of Exp " + theSUID);
}
 
Example 13
Project: Squid   File: Count.java   View Source Code Vote up 5 votes
private void readObject(
        ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    ObjectStreamClass myObject = ObjectStreamClass.lookup(Class.forName(Count.class.getCanonicalName()));
    long theSUID = myObject.getSerialVersionUID();
    System.out.println("Customized De-serialization of Count " + theSUID);
}
 
Example 14
Project: Squid   File: Max.java   View Source Code Vote up 5 votes
private void readObject(
        ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    ObjectStreamClass myObject = ObjectStreamClass.lookup(Class.forName(Max.class.getCanonicalName()));
    long theSUID = myObject.getSerialVersionUID();
    System.out.println("Customized De-serialization of Max " + theSUID);
}
 
Example 15
Project: OpenJSharp   File: SerialVer.java   View Source Code Vote up 5 votes
static String resolveClass(String classname) throws ClassNotFoundException {
    Class<?> cl = Class.forName(classname, false, loader);
    ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
    if (desc != null) {
        return "    private static final long serialVersionUID = " +
            desc.getSerialVersionUID() + "L;";
    } else {
        return null;
    }
}
 
Example 16
Project: jdk8u-jdk   File: SerialVer.java   View Source Code Vote up 5 votes
static String resolveClass(String classname) throws ClassNotFoundException {
    Class<?> cl = Class.forName(classname, false, loader);
    ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
    if (desc != null) {
        return "    private static final long serialVersionUID = " +
            desc.getSerialVersionUID() + "L;";
    } else {
        return null;
    }
}
 
Example 17
Project: openjdk-jdk10   File: SerialVer.java   View Source Code Vote up 5 votes
static String resolveClass(String classname) throws ClassNotFoundException {
    Class<?> cl = Class.forName(classname, false, loader);
    ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
    if (desc != null) {
        return "    private static final long serialVersionUID = " +
            desc.getSerialVersionUID() + "L;";
    } else {
        return null;
    }
}
 
Example 18
Project: incubator-netbeans   File: NbObjectInputStream.java   View Source Code Vote up 4 votes
/** Provides a special handling for renaming of serialized classes.
 * <P>
 * Often, as the time goes the serialized classes evolve. They can be moved
 * to new packages, renamed or changed (by a mistake) to not reflect the
 * version of class stored in previous sessions.
 * <P>
 * This method deals with some of this incompatibilites and provides the
 * module owners a way how to fix some of them.
 * <P>
 * When a class is read, the <link>Utilities.translate</link> is consulted
 * to find out what whether the name of the class is listed there and
 * what new value is assigned to it. This allows complete rename of the
 * serialized class. For example:
 * <code>org.netbeans.core.NbMainExplorer</code>
 * can be renamed to
 * <code>org.netbeans.core.ui.NbExp</code> - of course supposing that
 * the new class is able to read the serialized fields of the old one.
 * <P>
 * Another useful feature of this method is the ability to supress wrong
 * <code>serialVersionUID</code>. This was causing us a lot of problems,
 * because people were forgetting to specify the <code>serialVersionUID</code>
 * field in their sources and then it was hard to recover from it. Right
 * now we have a solution: Just use <link>Utilities.translate</link> framework
 * to assing your class <code>org.yourpackage.YourClass</code> the same
 * name as it had e.g. <code>org.yourpackage.YourClass</code>. This will
 * be interpreted by this method as a hit to suppress <code>serialVersionUID</code>
 * and the <code>NbObjectInputStream</code> will ignore its value.
 * <P>
 * Please see <link>Utilities.translate</link> to learn how your module
 * can provide list of classes that changed name or want to suppress <code>serialVersionUID</code>.
 *
 */
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
    ObjectStreamClass ose = super.readClassDescriptor();

    String name = ose.getName();
    String newN = BaseUtilities.translate(name);

    if (name == newN) {
        // no translation
        return ose;
    }

    // otherwise reload the ObjectStreamClass to contain the local copy
    ClassLoader cl = getNBClassLoader();
    Class clazz = Class.forName(newN, false, cl);

    ObjectStreamClass newOse = ObjectStreamClass.lookup(clazz);

    // #28021 - it is possible that lookup return null. In that case the conversion
    // table contains class which is not Serializable or Externalizable.
    if (newOse == null) {
        throw new java.io.NotSerializableException(newN);
    }

    return newOse;
}
 
Example 19
Project: JDigitalSimulator   File: Utilities.java   View Source Code Vote up 4 votes
@Override protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
	ObjectStreamClass descriptor = super.readClassDescriptor(); String name = descriptor.getName();
	if(name.contains(LEGACY_PACKAGE_PREFIX)) descriptor = ObjectStreamClass.lookup(Class.forName(replaceLegacyPackage(name), false, alternateClassLoader));
	return descriptor;
}
 
Example 20
Project: neoscada   File: AbstractIoBuffer.java   View Source Code Vote up 4 votes
/**
 * {@inheritDoc}
 */
@Override
public Object getObject(final ClassLoader classLoader) throws ClassNotFoundException {
    if (!prefixedDataAvailable(4)) {
        throw new BufferUnderflowException();
    }

    int length = getInt();
    if (length <= 4) {
        throw new BufferDataException("Object length should be greater than 4: " + length);
    }

    int oldLimit = limit();
    limit(position() + length);
    try {
        ObjectInputStream in = new ObjectInputStream(asInputStream()) {
            @Override
            protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
                int type = read();
                if (type < 0) {
                    throw new EOFException();
                }
                switch (type) {
                case 0: // NON-Serializable class or Primitive types
                    return super.readClassDescriptor();
                case 1: // Serializable class
                    String className = readUTF();
                    Class<?> clazz = Class.forName(className, true, classLoader);
                    return ObjectStreamClass.lookup(clazz);
                default:
                    throw new StreamCorruptedException("Unexpected class descriptor type: " + type);
                }
            }

            @Override
            protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
                String name = desc.getName();
                try {
                    return Class.forName(name, false, classLoader);
                } catch (ClassNotFoundException ex) {
                    return super.resolveClass(desc);
                }
            }
        };
        return in.readObject();
    } catch (IOException e) {
        throw new BufferDataException(e);
    } finally {
        limit(oldLimit);
    }
}