List of usage examples for java.io ObjectStreamClass getName
public String getName()
From source file:org.ajax4jsf.application.AjaxStateManager.java
private static final Object handleRestoreState(FacesContext context, Object state) { if (ContextInitParameters.isSerializeServerState(context)) { ObjectInputStream ois = null; try {/*from w w w . ja v a 2 s. co m*/ ois = new ObjectInputStream(new ByteArrayInputStream((byte[]) state)) { @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { String name = desc.getName(); try { return Class.forName(name, true, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException cnfe) { Class<?> clazz = PRIMITIVE_CLASSES.get(name); if (clazz != null) { return clazz; } else { throw cnfe; } } } }; return ois.readObject(); } catch (Exception e) { throw new FacesException(e); } finally { if (ois != null) { try { ois.close(); } catch (IOException ignored) { } } } } else { return state; } }
From source file:org.apache.batchee.container.util.TCCLObjectInputStream.java
@Override protected Class<?> resolveClass(final ObjectStreamClass desc) throws ClassNotFoundException { return Class.forName(BLACKLIST_CLASSES.check(desc.getName()), false, tccl); }
From source file:org.apache.ignite.GridTestIoUtils.java
/** * Deserializes passed in bytes using provided class loader. * * @param <T> Type of result object. * @param bytes Object bytes to deserialize. * @param clsLdr Class loader.// www .j a v a 2 s.c o m * @return Deserialized object. * @throws IOException If deserialization failed. * @throws ClassNotFoundException If deserialization failed. */ @SuppressWarnings({ "unchecked" }) public static <T> T deserializeJdk(byte[] bytes, final ClassLoader clsLdr) throws IOException, ClassNotFoundException { ObjectInputStream in = null; try { in = new ObjectInputStream(new ByteArrayInputStream(bytes)) { @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws ClassNotFoundException { return clsLdr.loadClass(desc.getName()); } }; return (T) in.readObject(); } finally { close(in); } }
From source file:org.apache.openejb.client.EjbObjectInputStream.java
@Override protected Class<?> resolveClass(final ObjectStreamClass classDesc) throws IOException, ClassNotFoundException { final String n = RESOLVER_ATOMIC_REFERENCE.get().check(classDesc.getName()); final ClassLoader classloader = getClassloader(); try {/*from ww w . j ava2 s . com*/ return Class.forName(n, false, classloader); } catch (ClassNotFoundException e) { if (n.equals("boolean")) { return boolean.class; } if (n.equals("byte")) { return byte.class; } if (n.equals("char")) { return char.class; } if (n.equals("short")) { return short.class; } if (n.equals("int")) { return int.class; } if (n.equals("long")) { return long.class; } if (n.equals("float")) { return float.class; } if (n.equals("double")) { return double.class; } //Last try - Let runtime try and find it. return Class.forName(n, false, null); } }
From source file:org.apache.openejb.core.rmi.BlacklistClassResolver.java
public final ObjectStreamClass check(final ObjectStreamClass classDesc) { check(classDesc.getName()); return classDesc; }
From source file:org.apache.sling.distribution.packaging.impl.DistributionPackageUtils.java
private static ObjectInputStream getSafeObjectInputStream(InputStream inputStream) throws IOException { final Class[] acceptedClasses = new Class[] { HashMap.class, HashSet.class, String.class, String[].class, Long.class, Number.class, Boolean.class, Enum.class, DistributionRequestType.class }; return new ObjectInputStream(inputStream) { @Override// w ww. j av a 2 s .com protected Class<?> resolveClass(ObjectStreamClass osc) throws IOException, ClassNotFoundException { String className = osc.getName(); for (Class clazz : acceptedClasses) { if (clazz.getName().equals(className)) { return super.resolveClass(osc); } } throw new InvalidClassException("Class name not accepted: " + className); } }; // TODO: replace with the following lines when switching to commons-io-2.5 // return new ValidatingObjectInputStream(inputStream) // .accept(acceptedClasses); }
From source file:org.echocat.nodoodle.transport.HandlerUnpacker.java
protected Handler<?> loadInstance(SplitResult splitResult, final ClassLoader classLoader) throws IOException { if (splitResult == null) { throw new NullPointerException(); }//w w w . ja v a2s. co m if (classLoader == null) { throw new NullPointerException(); } final Attributes extensionAttributes = splitResult.manifest.getAttributes(MANIFEST_EXTENSION_NAME); if (extensionAttributes == null) { throw new IOException("There is no valid manifest in the provided jar."); } final Object dataFile = extensionAttributes.get(MANIFEST_DATE_FILE); if (!(dataFile instanceof String)) { throw new IOException("There is no valid " + MANIFEST_DATE_FILE + " attribute defined in manifest."); } final InputStream inputStream = classLoader.getResourceAsStream((String) dataFile); if (inputStream == null) { throw new FileNotFoundException("Could not find the resource " + dataFile + " which was defined by " + MANIFEST_DATE_FILE + " manifest entry of provided jar file."); } try { final ObjectInputStream ois = new ObjectInputStream(inputStream) { @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws ClassNotFoundException { return classLoader.loadClass(desc.getName()); } }; final Object result; try { result = ois.readObject(); } catch (Exception e) { throw new IOException("Could not parse the resource " + dataFile + " which was defined by " + MANIFEST_DATE_FILE + " manifest entry of provided jar file.", e); } if (!(result instanceof Handler)) { throw new IOException("The resource " + dataFile + " which was defined by " + MANIFEST_DATE_FILE + " manifest entry of provided jar file does contain " + result + " and not an object of type " + Handler.class.getName() + "."); } return (Handler) result; } finally { IOUtils.closeQuietly(inputStream); } }
From source file:org.eclipse.dawnsci.doe.DOEUtils.java
/** * Creates a clone of any serializable object. Collections and arrays may be cloned if the entries are serializable. * Caution super class members are not cloned if a super class is not serializable. */// ww w . j a v a 2 s . c om public static <T extends Serializable> T deepClone(T toClone, final ClassLoader classLoader) throws Exception { if (null == toClone) return null; ByteArrayOutputStream bOut = new ByteArrayOutputStream(); ObjectOutputStream oOut = new ObjectOutputStream(bOut); oOut.writeObject(toClone); oOut.close(); ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray()); bOut.close(); ObjectInputStream oIn = new ObjectInputStream(bIn) { /** * What we are saying with this is that either the class loader or any of the beans added using extension * points classloaders should be able to find the class. */ @Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { try { return Class.forName(desc.getName(), false, classLoader); } catch (Exception ne) { ne.printStackTrace(); } return null; } }; bIn.close(); // the whole idea is to create a clone, therefore the readObject must // be the same type in the toClone, hence of T @SuppressWarnings("unchecked") T copy = (T) oIn.readObject(); oIn.close(); return copy; }
From source file:org.netbeans.jcode.util.PreferenceUtils.java
@Override protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { try {/* w ww . j a v a2 s. co m*/ String name = desc.getName(); return Class.forName(name, false, classLoader); } catch (ClassNotFoundException e) { return super.resolveClass(desc); } }
From source file:org.nibblesec.tools.SerialKiller.java
@Override protected Class<?> resolveClass(ObjectStreamClass serialInput) throws IOException, ClassNotFoundException { String[] blacklist = config.getStringArray("blacklist.regexp"); String[] whitelist = config.getStringArray("whitelist.regexp"); //Enforce SerialKiller's blacklist for (String blackRegExp : blacklist) { Pattern blackPattern = Pattern.compile(blackRegExp); Matcher blackMatcher = blackPattern.matcher(serialInput.getName()); if (blackMatcher.find()) { throw new InvalidClassException("[!] Blocked by SerialKiller's blacklist '" + blackRegExp + "'. Match found for '" + serialInput.getName() + "'"); }// w ww . java 2 s .c o m } //Enforce SerialKiller's whitelist boolean safeClass = false; for (String whiteRegExp : whitelist) { Pattern whitePattern = Pattern.compile(whiteRegExp); Matcher whiteMatcher = whitePattern.matcher(serialInput.getName()); if (whiteMatcher.find()) { safeClass = true; } } if (!safeClass) { throw new InvalidClassException( "[!] Blocked by SerialKiller's whitelist. No match found for '" + serialInput.getName() + "'"); } return super.resolveClass(serialInput); }