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

The following examples show how to use java.io.ObjectStreamClass#getName() . 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 check out the related API usage on the sidebar.
Example 1
Source File: TestObjectStreamClass.java    From hottub with GNU General Public License v2.0 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 2
Source File: TestObjectStreamClass.java    From jdk8u-jdk with GNU General Public License v2.0 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 3
Source File: TestObjectStreamClass.java    From TencentKona-8 with GNU General Public License v2.0 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 4
Source File: ObjectInputStreamWithLoader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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 5
Source File: StatelessJavaSerializer.java    From beam with 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 6
Source File: ObjectInputStreamWithLoader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@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 7
Source File: TransferableProxy.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 8
Source File: InternalDataSerializer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: FailureAtomicity.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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 10
Source File: RMIConnector.java    From jdk8u-dev-jdk with GNU General Public License v2.0 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 11
Source File: TransferableProxy.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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 12
Source File: Utils.java    From gemfirexd-oss with 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
Source File: Beans.java    From jdk-1.7-annotated with 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 14
Source File: Beans.java    From dragonwell8_jdk with GNU General Public License v2.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 15
Source File: PreferenceUtils.java    From jeddict with 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 16
Source File: RMIConnector.java    From JDKSourceCode1.8 with 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 17
Source File: Beans.java    From openjdk-8-source with GNU General Public License v2.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 18
Source File: Beans.java    From Bytecoder with 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 19
Source File: CustomObjectInputStream.java    From Tomcat8-Source-Read with MIT License 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 20
Source File: ClassFromSerializationReader.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 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());
}