Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

In this page you can find the example usage for java.lang Exception getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:de.micromata.genome.gwiki.web.GWikiServlet.java

public static boolean isIgnorableAppServeIOException(Exception ex) {
    return ex.getClass().getName().contains("RuntimeIOException") == true
            || ex.getClass().getName().contains("EofException") == true;
}

From source file:org.fcrepo.server.storage.GSearchDOManager.java

/**
 * Read the remainder of the given stream as a String and return it, or an
 * error message if we encounter an error.
 *///from ww w  . j a v a2s  .  com
private static String getString(InputStream in) {
    try {
        StringBuffer out = new StringBuffer();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = reader.readLine();
        while (line != null) {
            out.append(line + "\n");
            line = reader.readLine();
        }
        return out.toString();
    } catch (Exception e) {
        return "[Error reading response body: " + e.getClass().getName() + ": " + e.getMessage() + "]";
    }
}

From source file:info.magnolia.cms.exchange.simple.Transporter.java

/**
 * http form multipart form post/* w  ww.j a  v a  2s.  c  o  m*/
 * @param connection
 * @param activationContent
 * @throws ExchangeException
 */
public static void transport(URLConnection connection, ActivationContent activationContent)
        throws ExchangeException {
    FileInputStream fis = null;
    DataOutputStream outStream = null;
    try {
        byte[] buffer = new byte[BUFFER_SIZE];
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setUseCaches(false);
        connection.setRequestProperty("Content-type", "multipart/form-data; boundary=" + BOUNDARY);
        connection.setRequestProperty("Cache-Control", "no-cache");

        outStream = new DataOutputStream(connection.getOutputStream());
        outStream.writeBytes("--" + BOUNDARY + "\r\n");

        // set all resources from activationContent
        Iterator fileNameIterator = activationContent.getFiles().keySet().iterator();
        while (fileNameIterator.hasNext()) {
            String fileName = (String) fileNameIterator.next();
            fis = new FileInputStream(activationContent.getFile(fileName));
            outStream.writeBytes("content-disposition: form-data; name=\"" + fileName + "\"; filename=\""
                    + fileName + "\"\r\n");
            outStream.writeBytes("content-type: application/octet-stream" + "\r\n\r\n");
            while (true) {
                synchronized (buffer) {
                    int amountRead = fis.read(buffer);
                    if (amountRead == -1) {
                        break;
                    }
                    outStream.write(buffer, 0, amountRead);
                }
            }
            fis.close();
            outStream.writeBytes("\r\n" + "--" + BOUNDARY + "\r\n");
        }
        outStream.flush();
        outStream.close();

        log.debug("Activation content sent as multipart/form-data");
    } catch (Exception e) {
        throw new ExchangeException(
                "Simple exchange transport failed: " + ClassUtils.getShortClassName(e.getClass()), e);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
                log.error("Exception caught", e);
            }
        }
        if (outStream != null) {
            try {
                outStream.close();
            } catch (IOException e) {
                log.error("Exception caught", e);
            }
        }
    }

}

From source file:com.sunchenbin.store.feilong.core.text.NumberFormatUtil.java

/**
 *  {@link Number}  {@link RoundingMode} numberPattern?.
 *
 * @param value//from   ww w . j  a  v a 2 s. c  om
 *            the value
 * @param numberPattern
 *            the pattern {@link NumberPattern}
 * @param roundingMode
 *            ?{@link RoundingMode}
 * @return  null
 * @see NumberPattern
 * @see DecimalFormat
 * @see <a href="../util/NumberUtil.html#RoundingMode">JAVA 8??</a>
 */
public static String format(Number value, String numberPattern, RoundingMode roundingMode) {
    if (null == value) {
        throw new NullPointerException("the value is null or empty!");
    }

    if (null == numberPattern) {
        throw new NullPointerException("the numberPattern is null or empty!");
    }
    try {
        // applyPattern(pattern, false)
        DecimalFormat decimalFormat = new DecimalFormat(numberPattern);

        // ? RoundingMode.HALF_EVEN
        // ?,?.?,?.??,?,??.???1?,???.
        // 1.15>1.2 1.25>1.2
        if (null != roundingMode) {
            decimalFormat.setRoundingMode(roundingMode);
        }
        String format = decimalFormat.format(value);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("value:[{}], pattern:[{}],return:[{}],decimalFormat.toLocalizedPattern():[{}]", value,
                    numberPattern, format, decimalFormat.toLocalizedPattern()//?? Format ????. 
            );
        }
        return format;
    } catch (Exception e) {
        Object[] objects = { e.getMessage(), value, numberPattern };
        LOGGER.error("{},value:[{}],pattern:[{}]", objects);
        LOGGER.error(e.getClass().getName(), e);
    }
    return StringUtils.EMPTY;
}

From source file:com.clustercontrol.collect.util.CollectDataUtil.java

private static Integer getId(String itemName, String displayName, String monitorId, String facilityId,
        JpaTransactionManager jtm) {//from  w w w  .  java 2  s  .  co  m
    CollectKeyInfo collectKeyInfo = null;
    try {
        // collectKeyInfo(?collectorid)?????????????
        collectKeyInfo = QueryUtil
                .getCollectKeyPK(new CollectKeyInfoPK(itemName, displayName, monitorId, facilityId));
        if (collectKeyInfo == null) {
            throw new CollectKeyNotFound();
        }
        return collectKeyInfo.getCollectorid();
    } catch (CollectKeyNotFound e) {

        // collecorid??????????
        synchronized (maxLock) {
            if (maxId == null) {
                maxId = QueryUtil.getMaxId();
                if (maxId == null) {
                    maxId = -1;
                }
            }
            maxId++;
            try {
                HinemosEntityManager em = jtm.getEntityManager();
                collectKeyInfo = new CollectKeyInfo(itemName, displayName, monitorId, facilityId, maxId);
                em.persist(collectKeyInfo);
                em.flush();
                return collectKeyInfo.getCollectorid();
            } catch (Exception e1) {
                m_log.warn("put() : " + e1.getClass().getSimpleName() + ", " + e1.getMessage(), e1);
                if (jtm != null) {
                    jtm.rollback();
                }
            }
        }
    }
    m_log.warn("getId : error");
    return null;
}

From source file:com.clustercontrol.systemlog.service.SystemLogNotifier.java

/**
 * ?????????//from  ww  w  .ja va 2 s  .  co  m
 *
 * @param msg 
 * @param logmsg syslog
 * @param moninfo 
 * @param filterInfo 
 * @param facilityID ID
 * @param nodeName ??
 * @return 
 *
 * @since 1.0.0
 */
private static OutputBasicInfo makeMessage(String receiverId, String msg, SyslogMessage syslog,
        MonitorInfo monInfo, MonitorStringValueInfo filterInfo, String facilityId, String nodeName) {

    m_log.debug("Make ObjectMsg");

    OutputBasicInfo output = new OutputBasicInfo();

    output.setMonitorId(filterInfo.getMonitorId());
    output.setFacilityId(facilityId);

    output.setPluginId(HinemosModuleConstant.MONITOR_SYSTEMLOG);

    // ????????????
    output.setSubKey(filterInfo.getPattern());

    if (FacilityTreeAttributeConstant.UNREGISTERED_SCOPE.equals(facilityId)) {
        //?????????
        output.setScopeText(nodeName);
    } else {
        // ??]
        try {
            m_log.debug("call getFacilityPath.");
            String facilityPath = new RepositoryControllerBean().getFacilityPath(facilityId, null);
            m_log.debug("called getFacilityPath.");

            output.setScopeText(facilityPath);
        } catch (Exception e) {
            m_log.warn("makeMessage() cannot get facility path.(facilityId = " + facilityId + ") : "
                    + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        }
    }

    output.setApplication(monInfo.getApplication());

    // ?#[LOG_LINE]???????
    // ???
    if (filterInfo.getMessage() != null) {
        String str = filterInfo.getMessage().replace("#[LOG_LINE]", syslog.message);
        //DB?
        int maxLen = HinemosPropertyUtil.getHinemosPropertyNum("monitor.log.line.max.length", Long.valueOf(256))
                .intValue();
        if (str.length() > maxLen) {
            str = str.substring(0, maxLen);
        }
        output.setMessage(str);
    }

    output.setMessageOrg(msg);
    output.setPriority(filterInfo.getPriority());
    output.setGenerationDate(syslog.date);

    if (receiverId != null && !"".equals(receiverId)) {
        output.setMultiId(receiverId);
    }

    return output;
}

From source file:Main.java

/**
 * make a useful message from an exception without the stack track
 *//*  w w  w  . j a  v  a2s .  c o  m*/
public static String formatException(String message, Exception e) {
    StringBuilder builder = new StringBuilder();
    if (message != null) {
        builder.append(message);
        if (e != null) {
            builder.append(" - ");
        }
    }

    if (e != null) {
        builder.append(e.getClass().getSimpleName());

        String exceptionMessage = e.getMessage();
        if (exceptionMessage != null) {
            builder.append(": ");
            builder.append(exceptionMessage);
        }

        for (Throwable cause = e.getCause(); cause != null; cause = cause.getCause()) {
            builder.append(" (cause ");
            builder.append(cause.getClass().getSimpleName());
            String causeMessage = e.getMessage();
            if (causeMessage != null) {
                builder.append(": ");
                builder.append(exceptionMessage);
            }
            builder.append(")");
        }
    }

    return builder.toString();
}

From source file:com.feilong.commons.core.lang.reflect.FieldUtil.java

/**
 *  Field ?? Class ?.//  w  w w. j  a  v  a2 s. c om
 * 
 * @param clz
 *            clz
 * @param name
 *            ??
 * @return  Field ?? Class ?
 * @throws ReflectException
 *             the reflect exception
 * @see java.lang.Class#getDeclaredField(String)
 */
public static Field getDeclaredField(Class<?> clz, String name) throws ReflectException {
    try {
        Field field = clz.getDeclaredField(name);
        return field;
    } catch (Exception e) {
        log.error(e.getClass().getName(), e);
        throw new ReflectException(e);
    }
}

From source file:com.feilong.commons.core.lang.reflect.FieldUtil.java

/**
 * ./*from   w ww .j a  va2 s . co m*/
 * 
 * @param owner
 *            the owner
 * @param fieldName
 *            
 * @param value
 *            
 * @throws ReflectException
 *             the reflect exception
 * @see java.lang.Object#getClass()
 * @see java.lang.Class#getField(String)
 * @see java.lang.reflect.Field#set(Object, Object)
 */
public static void setProperty(Object owner, String fieldName, Object value) throws ReflectException {
    try {
        Class<?> ownerClass = owner.getClass();
        Field field = ownerClass.getField(fieldName);
        field.set(ownerClass, value);
    } catch (Exception e) {
        log.error(e.getClass().getName(), e);
        throw new ReflectException(e);
    }
}

From source file:com.sunchenbin.store.feilong.core.bean.PropertyUtil.java

/**
 * <code>bean</code> <span style="color:green">?</span>,??/Map.
 * /* w ww. ja  v a 2s . co  m*/
 * <p>
 * ???class,Object??,classjava.lang.Object
 * </p>
 * 
 * <h3>?:</h3>
 * 
 * <blockquote>
 * <ol>
 * <li>?bean class {@link java.beans.PropertyDescriptor}</li>
 * <li>, {@link java.beans.PropertyDescriptor#getReadMethod()}</li>
 * <li> name and {@link org.apache.commons.beanutils.PropertyUtilsBean#getProperty(Object, String)} map</li>
 * </ol>
 * </blockquote>
 *
 * @param bean
 *            Bean whose properties are to be extracted
 * @return The set of properties for the bean
 * @see org.apache.commons.beanutils.BeanUtils#describe(Object)
 * @see org.apache.commons.beanutils.PropertyUtils#describe(Object)
 * @see com.sunchenbin.store.feilong.core.bean.BeanUtil#describe(Object)
 */
public static Map<String, Object> describe(Object bean) {
    try {
        //Return the entire set of properties for which the specified bean provides a read method.
        return PropertyUtils.describe(bean);
    } catch (Exception e) {
        LOGGER.error(e.getClass().getName(), e);
        throw new BeanUtilException(e);
    }
}