cn.hutool.core.exceptions.UtilException Java Examples
The following examples show how to use
cn.hutool.core.exceptions.UtilException.
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: BeanConverter.java From WeBASE-Collect-Bee with Apache License 2.0 | 5 votes |
public IdEntity convertBOToEntity(CommonBO bo, String type) throws InstantiationException, IllegalAccessException, UtilException { IdEntity entity = (IdEntity) ClassLoaderUtil .loadClass("com.webank.webasebee.db.generated.entity." + type + "." + bo.getIdentifier()).newInstance(); BeanUtil.copyProperties(bo, entity); return entity; }
Example #2
Source File: BeanConverter.java From WeBASE-Collect-Bee with Apache License 2.0 | 5 votes |
public List<IdEntity> convertToEntities(Collection<CommonBO> bos, String type) { List<IdEntity> list = new ArrayList<>(bos.size()); bos.forEach(bo -> { try { list.add(convertBOToEntity(bo, type)); } catch (InstantiationException | IllegalAccessException | UtilException e) { log.error("Bean convert error", e); } }); return list; }
Example #3
Source File: ServletUtils.java From yue-library with Apache License 2.0 | 5 votes |
/** * 返回数据给客户端 * * @param text 返回的内容 * @param contentType 返回的类型 */ public static void write(String text, String contentType) { HttpServletResponse response = getResponse(); response.setContentType(contentType); Writer writer = null; try { writer = response.getWriter(); writer.write(text); writer.flush(); } catch (IOException e) { throw new UtilException(e); } finally { IoUtil.close(writer); } }
Example #4
Source File: ServletUtils.java From yue-library with Apache License 2.0 | 5 votes |
/** * 返回数据给客户端 * * @param in 需要返回客户端的内容 * @param bufferSize 缓存大小 */ public static void write(InputStream in, int bufferSize) { ServletOutputStream out = null; try { out = getResponse().getOutputStream(); IoUtil.copy(in, out, bufferSize); } catch (IOException e) { throw new UtilException(e); } finally { IoUtil.close(out); IoUtil.close(in); } }
Example #5
Source File: BeanCopier.java From spring-cloud-shop with MIT License | 4 votes |
/** * 值提供器转Bean * * @param valueProvider 值提供器 * @param bean Bean */ private void valueProviderToBean(ValueProvider<String> valueProvider, Object bean) { if (null == valueProvider) { return; } Class<?> actualEditable = bean.getClass(); if (copyOptions.editable != null) { // 检查限制类是否为target的父类或接口 if (!copyOptions.editable.isInstance(bean)) { throw new IllegalArgumentException(StrUtil.format("Target class [{}] not assignable to Editable class [{}]", bean.getClass().getName(), copyOptions.editable.getName())); } actualEditable = copyOptions.editable; } final HashSet<String> ignoreSet = (null != copyOptions.ignoreProperties) ? CollUtil.newHashSet(copyOptions.ignoreProperties) : null; final Map<String, String> fieldReverseMapping = copyOptions.getReversedMapping(); final Collection<BeanDesc.PropDesc> props = BeanUtil.getBeanDesc(actualEditable).getProps(); String fieldName; Object value; Method setterMethod; Class<?> propClass; for (BeanDesc.PropDesc prop : props) { // 获取值 fieldName = prop.getFieldName(); if (CollUtil.contains(ignoreSet, fieldName)) { // 目标属性值被忽略或值提供者无此key时跳过 continue; } final String providerKey = mappingKey(fieldReverseMapping, fieldName); if (!valueProvider.containsKey(providerKey)) { // 无对应值可提供 continue; } setterMethod = prop.getSetter(); if (null == setterMethod) { // Setter方法不存在跳过 continue; } value = valueProvider.value(providerKey, TypeUtil.getFirstParamType(setterMethod)); // 如果是字符串 if (value instanceof String) { String v = (String) value; // 字符串为空,则跳过 if (StrUtil.isBlank(v) && copyOptions.ignoreNullValue) { continue; } } if (null == value && copyOptions.ignoreNullValue) { // 当允许跳过空时,跳过 continue; } try { // valueProvider在没有对值做转换且当类型不匹配的时候,执行默认转换 propClass = prop.getFieldClass(); if (!propClass.isInstance(value)) { value = Convert.convert(propClass, value); if (null == value && copyOptions.ignoreNullValue) { // 当允许跳过空时,跳过 continue; } } // 执行set方法注入值 setterMethod.invoke(bean, value); } catch (Exception e) { if (copyOptions.ignoreError) { // 忽略注入失败 continue; } else { throw new UtilException(e, "Inject [{}] error!", prop.getFieldName()); } } } }