Search in sources :

Example 6 with UnsyncByteArrayInputStream

use of com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream in project liferay-ide by liferay.

the class ClpSerializer method translateThrowable.

public static Throwable translateThrowable(Throwable throwable) {
    if (_useReflectionToTranslateThrowable) {
        try {
            UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(unsyncByteArrayOutputStream);
            objectOutputStream.writeObject(throwable);
            objectOutputStream.flush();
            objectOutputStream.close();
            UnsyncByteArrayInputStream unsyncByteArrayInputStream = new UnsyncByteArrayInputStream(unsyncByteArrayOutputStream.unsafeGetByteArray(), 0, unsyncByteArrayOutputStream.size());
            Thread currentThread = Thread.currentThread();
            ClassLoader contextClassLoader = currentThread.getContextClassLoader();
            ObjectInputStream objectInputStream = new ClassLoaderObjectInputStream(unsyncByteArrayInputStream, contextClassLoader);
            throwable = (Throwable) objectInputStream.readObject();
            objectInputStream.close();
            return throwable;
        } catch (ClassNotFoundException cnfe) {
            if (_log.isInfoEnabled()) {
                _log.info("Do not use reflection to translate throwable");
            }
            _useReflectionToTranslateThrowable = false;
        } catch (SecurityException se) {
            if (_log.isInfoEnabled()) {
                _log.info("Do not use reflection to translate throwable");
            }
            _useReflectionToTranslateThrowable = false;
        } catch (Throwable throwable2) {
            _log.error(throwable2, throwable2);
            return throwable2;
        }
    }
    Class<?> clazz = throwable.getClass();
    String className = clazz.getName();
    if (className.equals("com.liferay.opensocial.DuplicateGadgetURLException")) {
        return new com.liferay.opensocial.DuplicateGadgetURLException(throwable.getMessage(), throwable.getCause());
    }
    if (className.equals("com.liferay.opensocial.GadgetPortletCategoryNamesException")) {
        return new com.liferay.opensocial.GadgetPortletCategoryNamesException(throwable.getMessage(), throwable.getCause());
    }
    if (className.equals("com.liferay.opensocial.GadgetURLException")) {
        return new com.liferay.opensocial.GadgetURLException(throwable.getMessage(), throwable.getCause());
    }
    if (className.equals("com.liferay.opensocial.NoSuchGadgetException")) {
        return new com.liferay.opensocial.NoSuchGadgetException(throwable.getMessage(), throwable.getCause());
    }
    if (className.equals("com.liferay.opensocial.NoSuchOAuthConsumerException")) {
        return new com.liferay.opensocial.NoSuchOAuthConsumerException(throwable.getMessage(), throwable.getCause());
    }
    if (className.equals("com.liferay.opensocial.NoSuchOAuthTokenException")) {
        return new com.liferay.opensocial.NoSuchOAuthTokenException(throwable.getMessage(), throwable.getCause());
    }
    return throwable;
}
Also used : UnsyncByteArrayOutputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream) ClassLoaderObjectInputStream(com.liferay.portal.kernel.util.ClassLoaderObjectInputStream) ObjectOutputStream(java.io.ObjectOutputStream) UnsyncByteArrayInputStream(com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) ClassLoaderObjectInputStream(com.liferay.portal.kernel.util.ClassLoaderObjectInputStream)

Aggregations

UnsyncByteArrayInputStream (com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream)6 UnsyncByteArrayOutputStream (com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream)3 ClassLoaderObjectInputStream (com.liferay.portal.kernel.util.ClassLoaderObjectInputStream)3 InputStream (java.io.InputStream)3 ObjectInputStream (java.io.ObjectInputStream)3 ObjectOutputStream (java.io.ObjectOutputStream)3 PortalException (com.liferay.portal.kernel.exception.PortalException)2 SystemException (com.liferay.portal.kernel.exception.SystemException)2 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)2 KBArticle (com.liferay.knowledgebase.model.KBArticle)1 Element (com.liferay.portal.kernel.xml.Element)1 ServiceContext (com.liferay.portal.service.ServiceContext)1 DuplicateFileException (com.liferay.portlet.documentlibrary.DuplicateFileException)1