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 (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(PortalException.class.getName())) {
      return new PortalException();
    }

    if (className.equals(SystemException.class.getName())) {
      return new SystemException();
    }

    if (className.equals("com.ktree.timezone.model.dao.NoSuchWorldClockException")) {
      return new com.ktree.timezone.model.dao.NoSuchWorldClockException();
    }

    return throwable;
  }
  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.pushnotifications.NoSuchDeviceException")) {
      return new com.liferay.pushnotifications.NoSuchDeviceException(
          throwable.getMessage(), throwable.getCause());
    }

    return throwable;
  }
  protected void renderExclusive(
      HttpServletRequest request, HttpServletResponse response, ThemeDisplay themeDisplay)
      throws Exception {

    RenderRequestImpl renderRequestImpl =
        (RenderRequestImpl) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

    RenderResponseImpl renderResponseImpl =
        (RenderResponseImpl) request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);

    StringServletResponse stringResponse =
        (StringServletResponse) renderRequestImpl.getAttribute(WebKeys.STRING_SERVLET_RESPONSE);

    if (stringResponse == null) {
      stringResponse = (StringServletResponse) renderResponseImpl.getHttpServletResponse();

      Portlet portlet = processPortletRequest(request, response, PortletRequest.RENDER_PHASE);

      InvokerPortlet invokerPortlet = PortletInstanceFactoryUtil.create(portlet, null);

      invokerPortlet.render(renderRequestImpl, renderResponseImpl);

      if (Validator.isNull(stringResponse.getString())) {
        stringResponse.setString(null);
      }
    }

    renderResponseImpl.transferHeaders(response);

    if (stringResponse.isCalledGetOutputStream()) {
      UnsyncByteArrayOutputStream ubaos = stringResponse.getUnsyncByteArrayOutputStream();

      InputStream is = new UnsyncByteArrayInputStream(ubaos.unsafeGetByteArray(), 0, ubaos.size());

      ServletResponseUtil.sendFile(
          request,
          response,
          renderResponseImpl.getResourceName(),
          is,
          renderResponseImpl.getContentType());
    } else if (stringResponse.isCalledGetWriter()) {
      byte[] content = stringResponse.getString().getBytes(StringPool.UTF8);

      ServletResponseUtil.sendFile(
          request,
          response,
          renderResponseImpl.getResourceName(),
          content,
          renderResponseImpl.getContentType());
    }

    renderRequestImpl.cleanUp();
  }
  /**
   * This method only uses the default Commons HttpClient implementation when the URL object
   * represents a HTTP resource. The URL object could also represent a file or some JNDI resource.
   * In that case, the default Java implementation is used.
   *
   * @return A string representation of the resource referenced by the URL object
   */
  public String URLtoString(URL url) throws IOException {
    String xml = null;

    if (url != null) {
      String protocol = url.getProtocol().toLowerCase();

      if (protocol.startsWith(Http.HTTP) || protocol.startsWith(Http.HTTPS)) {

        return URLtoString(url.toString());
      }

      URLConnection urlConnection = url.openConnection();

      InputStream inputStream = urlConnection.getInputStream();

      UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();

      byte[] bytes = new byte[512];

      for (int i = inputStream.read(bytes, 0, 512); i != -1; i = inputStream.read(bytes, 0, 512)) {

        unsyncByteArrayOutputStream.write(bytes, 0, i);
      }

      xml =
          new String(
              unsyncByteArrayOutputStream.unsafeGetByteArray(),
              0,
              unsyncByteArrayOutputStream.size());

      inputStream.close();

      unsyncByteArrayOutputStream.close();
    }

    return xml;
  }