Java Code Examples for java.io.ObjectStreamClass

The following are top voted examples for showing how to use java.io.ObjectStreamClass. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: AgentWorkbench   File: ObjectInputStreamForClassLoadService.java   View source code 6 votes vote down vote up
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {

	if (this.utilityClass!=null) {
		try {
			Method method = this.utilityClass.getMethod("forName", String.class);
			Object returnObject = method.invoke(null, desc.getName());
			Class<?> returnClass = (Class<?>) returnObject;
			return returnClass;

		} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
			//ex.printStackTrace();
		}
	}
	return BaseClassLoadServiceUtility.forName(desc.getName());
}
 
Example 2
Project: EatDubbo   File: CompactedObjectInputStream.java   View source code 6 votes vote down vote up
@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 3
Project: ooso   File: DecompressibleInputStream.java   View source code 6 votes vote down vote up
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 4
Project: dubbo2   File: CompactedObjectInputStream.java   View source code 6 votes vote down vote up
@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 5
Project: myfaces-trinidad   File: ObjectInputStreamResolveClass.java   View source code 6 votes vote down vote up
protected Class<?> resolveClass(ObjectStreamClass desc)
                         throws IOException,
                                ClassNotFoundException
{
  Class<?> cls = null;
  String className = desc.getName();

  // if it is primitive class, for example, long.class
  // we resolve them by getting them from the hashMaps
  cls = _PRIMITIVE_CLASSES.get(className);

  if (null == cls)
  {
    // TRINIDAD-1062 It has been noticed that in OC4J and Weblogic that the
    // classes being resolved are having problems by not finding
    // them using the context class loader. Therefore, we are adding
    // this work-around until the problem with these application
    // servers can be better understood
    cls = ClassLoaderUtils.loadClass(desc.getName());
  }
  return cls;
}
 
Example 6
Project: letv   File: UnsafeAllocator.java   View source code 6 votes vote down vote up
public static UnsafeAllocator create() {
    try {
        Class cls = Class.forName("sun.misc.Unsafe");
        Field declaredField = cls.getDeclaredField("theUnsafe");
        declaredField.setAccessible(true);
        return new aj(cls.getMethod("allocateInstance", new Class[]{Class.class}), declaredField.get(null));
    } catch (Exception e) {
        try {
            Method declaredMethod = ObjectStreamClass.class.getDeclaredMethod("getConstructorId", new Class[]{Class.class});
            declaredMethod.setAccessible(true);
            int intValue = ((Integer) declaredMethod.invoke(null, new Object[]{Object.class})).intValue();
            Method declaredMethod2 = ObjectStreamClass.class.getDeclaredMethod("newInstance", new Class[]{Class.class, Integer.TYPE});
            declaredMethod2.setAccessible(true);
            return new ak(declaredMethod2, intValue);
        } catch (Exception e2) {
            try {
                Method declaredMethod3 = ObjectInputStream.class.getDeclaredMethod("newInstance", new Class[]{Class.class, Class.class});
                declaredMethod3.setAccessible(true);
                return new al(declaredMethod3);
            } catch (Exception e3) {
                return new am();
            }
        }
    }
}
 
Example 7
Project: OpenJSharp   File: ValueType.java   View source code 6 votes vote down vote up
/**
 * 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 8
Project: openjdk-jdk10   File: TestObjectStreamClass.java   View source code 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 9
Project: dubbox-hystrix   File: CompactedObjectInputStream.java   View source code 6 votes vote down vote up
@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 10
Project: jdk8u-jdk   File: ClassDesc.java   View source code 6 votes vote down vote up
/**
 * 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 11
Project: jdk8u-jdk   File: ProxyClassDesc.java   View source code 6 votes vote down vote up
/**
 * Write and read proxy 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[] descs = genDescs();

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

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, descs, ncycles);
    return System.currentTimeMillis() - start;
}
 
Example 12
Project: jdk8u-jdk   File: ProxyClassDesc.java   View source code 6 votes vote down vote up
/**
 * 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 13
Project: jdk8u-jdk   File: ProxyClassDesc.java   View source code 6 votes vote down vote up
/**
 * Run benchmark for given number of cycles.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, ObjectStreamClass[] descs, int ncycles)
    throws Exception
{
    int ndescs = descs.length;
    for (int i = 0; i < ncycles; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ndescs; j++) {
            oout.writeObject(descs[j]);
        }
        oout.flush();
        for (int j = 0; j < ndescs; j++) {
            oin.readObject();
        }
    }
}
 
Example 14
Project: jdk8u-jdk   File: TestObjectStreamClass.java   View source code 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 15
Project: openjdk-jdk10   File: ValueType.java   View source code 6 votes vote down vote up
/**
 * 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 16
Project: dubbocloud   File: CompactedObjectInputStream.java   View source code 6 votes vote down vote up
@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 17
Project: openjdk-jdk10   File: ClassDesc.java   View source code 6 votes vote down vote up
/**
 * 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 18
Project: openjdk-jdk10   File: ProxyClassDesc.java   View source code 6 votes vote down vote up
/**
 * Write and read proxy 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[] descs = genDescs();

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

    long start = System.currentTimeMillis();
    doReps(oout, oin, sbuf, descs, ncycles);
    return System.currentTimeMillis() - start;
}
 
Example 19
Project: openjdk-jdk10   File: ProxyClassDesc.java   View source code 6 votes vote down vote up
/**
 * 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 20
Project: openjdk-jdk10   File: ProxyClassDesc.java   View source code 6 votes vote down vote up
/**
 * Run benchmark for given number of cycles.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, ObjectStreamClass[] descs, int ncycles)
    throws Exception
{
    int ndescs = descs.length;
    for (int i = 0; i < ncycles; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ndescs; j++) {
            oout.writeObject(descs[j]);
        }
        oout.flush();
        for (int j = 0; j < ndescs; j++) {
            oin.readObject();
        }
    }
}
 
Example 21
Project: openjdk-jdk10   File: SuperclassDataLossTest.java   View source code 6 votes vote down vote up
protected Class resolveClass(ObjectStreamClass desc)
    throws IOException, ClassNotFoundException
{
    // resolve A's classdesc to class != B's superclass
    String name = desc.getName();
    if (ldr12A) {
        if (name.equals("A")) {
            return Class.forName(name, true, ldr1);
        } else if (name.equals("B")) {
            return Class.forName(name, true, ldr2);
        }
    } else {
        if (name.equals("B")) {
            return Class.forName(name, true, ldr1);
        } else if (name.equals("A")) {
            return Class.forName(name, true, ldr2);
        }
    }
    return super.resolveClass(desc);
}
 
Example 22
Project: Reer   File: ClassLoaderObjectInputStream.java   View source code 5 votes vote down vote up
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
    try {
        return Class.forName(desc.getName(), false, loader);
    } catch (ClassNotFoundException e) {
        return super.resolveClass(desc);
    }
}
 
Example 23
Project: Reer   File: PayloadSerializerObjectInputStream.java   View source code 5 votes vote down vote up
@Override
protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
    Class<?> aClass = readClass();
    ObjectStreamClass descriptor = ObjectStreamClass.lookupAny(aClass);
    if (descriptor == null) {
        throw new ClassNotFoundException(aClass.getName());
    }
    return descriptor;
}
 
Example 24
Project: openrasp   File: DeserializationHook.java   View source code 5 votes vote down vote up
/**
 * 反序列化监检测点
 *
 * @param objectStreamClass 反序列化的类的流对象
 */
public static void checkDeserializationClass(ObjectStreamClass objectStreamClass) {
    if (objectStreamClass != null) {
        String clazz = objectStreamClass.getName();
        if (clazz != null) {
            JSContext cx = JSContextFactory.enterAndInitContext();
            Scriptable params = cx.newObject(cx.getScope());
            params.put("clazz", params, clazz);
            HookHandler.doCheck(CheckParameter.Type.DESERIALIZATION, params);
        }
    }

}
 
Example 25
Project: Squid   File: Average.java   View source code 5 votes vote down vote up
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 26
Project: Squid   File: Exp.java   View source code 5 votes vote down vote up
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 27
Project: Squid   File: Count.java   View source code 5 votes vote down vote up
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 28
Project: Squid   File: Max.java   View source code 5 votes vote down vote up
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 29
Project: incubator-netbeans   File: NbObjectInputStream.java   View source code 5 votes vote down vote up
protected Class resolveClass(ObjectStreamClass v) throws IOException, ClassNotFoundException {
    ClassLoader cl = getNBClassLoader();

    try {
        return Class.forName(v.getName(), false, cl);
    } catch (ClassNotFoundException cnfe) {
        String msg = "Offending classloader: " + cl; // NOI18N
        Exceptions.attachMessage(cnfe, msg);
        throw cnfe;
    }
}
 
Example 30
Project: Robin_Java   File: SecurityObjectInputStream.java   View source code 5 votes vote down vote up
@Override
protected Class<?> resolveClass( ObjectStreamClass desc )
        throws IOException, ClassNotFoundException
{
    
    //System.out.println(desc.getName());
    if(!securityList.contains( desc.getName() )){
        throw new ClassNotFoundException( desc.getName() + " not found" );
    };
    return super.resolveClass( desc );
}
 
Example 31
Project: AgentWorkbench   File: SerialClone.java   View source code 5 votes vote down vote up
@Override
protected Class<?> resolveClass(ObjectStreamClass osc) throws IOException, ClassNotFoundException {
	Class<?> c = output.classQueue.poll();
	String expected = osc.getName();
	String found = (c == null) ? null : c.getName();
	if (!expected.equals(found)) {
		throw new InvalidClassException("Classes desynchronized: found " + found + " when expecting " + expected);
	}
	return c;
}
 
Example 32
Project: JRediClients   File: CustomObjectInputStream.java   View source code 5 votes vote down vote up
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
    try {
        String name = desc.getName();
        return Class.forName(name, false, classLoader);
    } catch (ClassNotFoundException e) {
        return super.resolveClass(desc);
    }
}
 
Example 33
Project: EatDubbo   File: CompactedObjectOutputStream.java   View source code 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 34
Project: Moenagade   File: ClassLoaderObjectInputStream.java   View source code 5 votes vote down vote up
/**
 * Resolve a class specified by the descriptor using the
 * specified ClassLoader or the super ClassLoader.
 *
 * @param objectStreamClass  descriptor of the class
 * @return the Class object described by the ObjectStreamClass
 * @throws IOException in case of an I/O error
 * @throws ClassNotFoundException if the Class cannot be found
 */
@Override
protected Class<?> resolveClass(ObjectStreamClass objectStreamClass)
        throws IOException, ClassNotFoundException {
    
    Class<?> clazz = Class.forName(objectStreamClass.getName(), false, classLoader);

    if (clazz != null) {
        // the classloader knows of the class
        return clazz;
    } else {
        // classloader knows not of class, let the super classloader do it
        return super.resolveClass(objectStreamClass);
    }
}
 
Example 35
Project: neoscada   File: AbstractIoBuffer.java   View source code 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public IoBuffer putObject(Object o) {
    int oldPos = position();
    skip(4); // Make a room for the length field.
    try {
        ObjectOutputStream out = new ObjectOutputStream(asOutputStream()) {
            @Override
            protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
                try {
                    Class<?> clz = Class.forName(desc.getName());
                    if (!Serializable.class.isAssignableFrom(clz)) { // NON-Serializable class
                        write(0);
                        super.writeClassDescriptor(desc);
                    } else { // Serializable class
                        write(1);
                        writeUTF(desc.getName());
                    }
                } catch (ClassNotFoundException ex) { // Primitive types
                    write(0);
                    super.writeClassDescriptor(desc);
                }
            }
        };
        out.writeObject(o);
        out.flush();
    } catch (IOException e) {
        throw new BufferDataException(e);
    }

    // Fill the length field
    int newPos = position();
    position(oldPos);
    putInt(newPos - oldPos - 4);
    position(newPos);
    return this;
}
 
Example 36
Project: tomcat7   File: CustomObjectInputStream.java   View source code 5 votes vote down vote up
/**
 * Load the local class equivalent of the specified stream class
 * description, by using the class loader assigned to this Context.
 *
 * @param classDesc Class description from the input stream
 *
 * @exception ClassNotFoundException if this class cannot be found
 * @exception IOException if an input/output error occurs
 */
@Override
public Class<?> resolveClass(ObjectStreamClass classDesc)
    throws ClassNotFoundException, IOException {

    String name = classDesc.getName();
    if (allowedClassNamePattern != null) {
        boolean allowed = allowedClassNamePattern.matcher(name).matches();
        if (!allowed) {
            boolean doLog = warnOnFailure && reportedClasses.add(name);
            String msg = sm.getString("customObjectInputStream.nomatch", name, allowedClassNameFilter);
            if (doLog) {
                log.warn(msg);
            } else if (log.isDebugEnabled()) {
                log.debug(msg);
            }
            throw new InvalidClassException(msg);
        }
    }

    try {
        return Class.forName(name, false, classLoader);
    } catch (ClassNotFoundException e) {
        try {
            // Try also the superclass because of primitive types
            return super.resolveClass(classDesc);
        } catch (ClassNotFoundException e2) {
            // Rethrow original exception, as it can have more information
            // about why the class was not found. BZ 48007
            throw e;
        }
    }
}
 
Example 37
Project: dubbo2   File: CompactedObjectOutputStream.java   View source code 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 38
Project: myfaces-trinidad   File: MyFacesObjectInputStream.java   View source code 5 votes vote down vote up
protected Class resolveClass(ObjectStreamClass desc)
    throws ClassNotFoundException, IOException
{
    try
    {
        return ClassUtils.classForName(desc.getName());
    }
    catch (ClassNotFoundException e)
    {
        return super.resolveClass(desc);
    }
}
 
Example 39
Project: Equella   File: PluginAwareObjectInputStream.java   View source code 5 votes vote down vote up
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException
{
	if (banned.contains(desc.getName()))
	{
		throw new RuntimeException("Class is banned: "+desc.getName());
	}
	int loaderNum = readByte();
	ClassLoader loader;
	if( loaderNum == 0 )
	{
		loader = Thread.currentThread().getContextClassLoader();
	}
	else if( loaderNum > loaders.size() )
	{
		String pluginId = readUTF();
		PluginClassResolver pluginService = PluginClassResolver.resolver();
		loader = pluginService.getLoaderForPluginId(pluginId);
		loaders.add(loader);
	}
	else
	{
		loader = loaders.get(loaderNum - 1);
	}
	try
	{
		return Class.forName(desc.getName(), false, loader);
	}
	catch( ClassNotFoundException cnfe )
	{
		return super.resolveClass(desc);
	}
}
 
Example 40
Project: lams   File: ClassLoaderObjectInputStream.java   View source code 5 votes vote down vote up
/**
 * Resolve a class specified by the descriptor using the
 * specified ClassLoader or the super ClassLoader.
 *
 * @param objectStreamClass  descriptor of the class
 * @return the Class object described by the ObjectStreamClass
 * @throws IOException in case of an I/O error
 * @throws ClassNotFoundException if the Class cannot be found
 */
@Override
protected Class<?> resolveClass(ObjectStreamClass objectStreamClass)
        throws IOException, ClassNotFoundException {
    
    Class<?> clazz = Class.forName(objectStreamClass.getName(), false, classLoader);

    if (clazz != null) {
        // the classloader knows of the class
        return clazz;
    } else {
        // classloader knows not of class, let the super classloader do it
        return super.resolveClass(objectStreamClass);
    }
}