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

The following examples show how to use java.io.ObjectStreamClass#getName() . 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
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 Project: beam   File: StatelessJavaSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) {
  try {
    return Class.forName(desc.getName(), false, classLoader);
  } catch (ClassNotFoundException e) {
    throw new RuntimeException("Could not find class: " + desc.getName(), e);
  }
}
 
Example 5
/**
 * 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 6
Source Project: Bytecoder   File: Beans.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Use the given ClassLoader rather than using the system class
 */
@SuppressWarnings("rawtypes")
protected Class resolveClass(ObjectStreamClass classDesc)
    throws IOException, ClassNotFoundException {

    String cname = classDesc.getName();
    return ClassFinder.resolveClass(cname, this.loader);
}
 
Example 7
/**
 * Use the given ClassLoader rather than using the system class
 */
@SuppressWarnings("rawtypes")
protected Class resolveClass(ObjectStreamClass classDesc)
    throws IOException, ClassNotFoundException {

    String cname = classDesc.getName();
    return ClassFinder.resolveClass(cname, this.loader);
}
 
Example 8
Source Project: JDKSourceCode1.8   File: RMIConnector.java    License: MIT License 5 votes vote down vote up
@Override
protected Class<?> resolveClass(ObjectStreamClass classDesc)
        throws IOException, ClassNotFoundException {
    String name = classDesc.getName();
    ReflectUtil.checkPackageAccess(name);
    return Class.forName(name, false, loader);
}
 
Example 9
Source Project: jeddict   File: PreferenceUtils.java    License: Apache License 2.0 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 10
/**
 * Use the given ClassLoader rather than using the system class
 */
@SuppressWarnings("rawtypes")
protected Class resolveClass(ObjectStreamClass classDesc)
    throws IOException, ClassNotFoundException {

    String cname = classDesc.getName();
    return ClassFinder.resolveClass(cname, this.loader);
}
 
Example 11
Source Project: jdk-1.7-annotated   File: Beans.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Use the given ClassLoader rather than using the system class
 */
protected Class resolveClass(ObjectStreamClass classDesc)
    throws IOException, ClassNotFoundException {

    String cname = classDesc.getName();
    return ClassFinder.resolveClass(cname, this.loader);
}
 
Example 12
Source Project: gemfirexd-oss   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Overriden version that uses the parametrized <code>ClassLoader</code> or the <code>ClassLoader</code>
 * of the current <code>Thread</code> to resolve the class.
 *
 * @param desc An instance of class <code>ObjectStreamClass</code>.
 * @return A <code>Class</code> object corresponding to <code>desc</code>.
 * @throws IOException            Any of the usual Input/Output exceptions.
 * @throws ClassNotFoundException If class of a serialized object cannot be found.
 */
@Override
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
    String name = desc.getName();
    try {
        return Class.forName(name, false, classLoader);
    } catch (ClassNotFoundException ex) {
        return Class.forName(name, false, Thread.currentThread().getContextClassLoader());
    }
}
 
Example 13
protected Class<?> resolveClass(ObjectStreamClass classDesc)
  throws IOException, ClassNotFoundException {
    String className = classDesc.getName();

    Set<String> s = new HashSet<String>(1);
    s.add(className);

    ClassLoader classLoader = map.get(s);
    if (classLoader != null) {
        return Class.forName(className, false, classLoader);
    } else {
        return super.resolveClass(classDesc);
    }
}
 
Example 14
@Override
protected Class<?> resolveClass(ObjectStreamClass classDesc)
        throws IOException, ClassNotFoundException {
    String name = classDesc.getName();
    ReflectUtil.checkPackageAccess(name);
    return Class.forName(name, false, loader);
}
 
Example 15
@Override
protected Class<?> resolveClass(ObjectStreamClass desc)
    throws IOException, ClassNotFoundException {
    try {
        return super.resolveClass(desc);
    } catch (ClassNotFoundException x) {
        String name = desc.getName();
        return Class.forName(name, false, loader);
    }
}
 
Example 16
@Override
protected Class resolveClass(ObjectStreamClass desc)
  throws IOException, ClassNotFoundException {

  String className = desc.getName();
 try {
    return getCachedClass(className);

  } catch (ClassNotFoundException ex) {
    return super.resolveClass(desc);
  }
}
 
Example 17
protected Class<?> resolveClass(ObjectStreamClass classDesc)
  throws IOException, ClassNotFoundException {
    String className = classDesc.getName();

    Set<String> s = new HashSet<String>(1);
    s.add(className);

    ClassLoader classLoader = map.get(s);
    if (classLoader != null) {
        return Class.forName(className, false, classLoader);
    } else {
        return super.resolveClass(classDesc);
    }
}
 
Example 18
@Override
protected Class<?> resolveClass(ObjectStreamClass aClass)
        throws IOException, ClassNotFoundException {
    if (loader == null) {
        return super.resolveClass(aClass);
    } else {
        String name = aClass.getName();
        ReflectUtil.checkPackageAccess(name);
        // Query the class loader ...
        return Class.forName(name, false, loader);
    }
}
 
Example 19
@Override
protected Class<?> resolveClass(ObjectStreamClass aClass)
        throws IOException, ClassNotFoundException {
    if (loader == null) {
        return super.resolveClass(aClass);
    } else {
        String name = aClass.getName();
        ReflectUtil.checkPackageAccess(name);
        // Query the class loader ...
        return Class.forName(name, false, loader);
    }
}
 
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());
}