Package com.xiaoleilu.hutool.exceptions

Examples of com.xiaoleilu.hutool.exceptions.UtilException


    }
   
    try {
      return new String(data, charset);
    } catch (UnsupportedEncodingException e) {
      throw new UtilException(e);
    }
  }
View Full Code Here


   
    byte[] data = null;
    try {
      data = StrUtil.isBlank(charset) ? content.getBytes() : content.getBytes(charset);
    } catch (UnsupportedEncodingException e) {
      throw new UtilException(StrUtil.format("Invalid charset [{}] !", charset), e);
    }
   
    return new ByteArrayInputStream(data);
  }
View Full Code Here

    String packagePath = packageName.replace(StrUtil.DOT, StrUtil.SLASH);
    Enumeration<URL> resources;
    try {
      resources = getClassLoader().getResources(packagePath);
    } catch (IOException e) {
      throw new UtilException(StrUtil.format("Loading classPath [{}] error!", packagePath), e);
    }
    Set<String> paths = new HashSet<String>();
    while(resources.hasMoreElements()) {
      paths.add(resources.nextElement().getPath());
    }
View Full Code Here

  @SuppressWarnings("unchecked")
  public static <T> T newInstance(String clazz) {
    try {
      return (T) Class.forName(clazz).newInstance();
    } catch (Exception e) {
      throw new UtilException(StrUtil.format("Instance class [{}] error!", clazz), e);
    }
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  public static <T> T newInstance(Class<?> clazz) {
    try {
      return (T) clazz.newInstance();
    } catch (Exception e) {
      throw new UtilException(StrUtil.format("Instance class [{}] error!", clazz), e);
    }
  }
View Full Code Here

      final ObjectOutputStream out = new ObjectOutputStream(byteOut);
      out.writeObject(obj);
      final ObjectInputStream in =new ObjectInputStream(new ByteArrayInputStream(byteOut.toByteArray()));
      return (T) in.readObject();
    } catch (Exception e) {
      throw new UtilException(e);
    }
  }
View Full Code Here

  public static Class<?> loadClass(String className, boolean isInitialized) {
    Class<?> clazz;
    try {
      clazz = Class.forName(className, isInitialized, getClassLoader());
    }catch (ClassNotFoundException e) {
      throw new UtilException(e);
    }
    return clazz;
  }
View Full Code Here

  public static Document readXML(File file) {
    if (file == null) {
      throw new NullPointerException("Xml file is null !");
    }
    if (file.exists() == false) {
      throw new UtilException("File [" + file.getAbsolutePath() + "] not a exist!");
    }
    if (file.isFile() == false) {
      throw new UtilException("[" + file.getAbsolutePath() + "] not a file!");
    }

    try {
      file = file.getCanonicalFile();
    } catch (IOException e) {
    }

    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
      final DocumentBuilder builder = dbf.newDocumentBuilder();
      return builder.parse(file);
    } catch (Exception e) {
      throw new UtilException("Parse xml file [" + file.getAbsolutePath() + "] error!", e);
    }
  }
View Full Code Here

   * @param charset
   * @return XML文档
   */
  public static Document parseXml(String xmlStr, String charset) {
    if (StrUtil.isBlank(xmlStr)) {
      throw new UtilException("Xml content string is empty !");
    }
    xmlStr = cleanInvalid(xmlStr);

    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
      final DocumentBuilder builder = dbf.newDocumentBuilder();
      return builder.parse(IoUtil.toStream(xmlStr, charset));
    } catch (Exception e) {
      throw new UtilException("Parse xml file [" + xmlStr + "] error!", e);
    }
  }
View Full Code Here

      // xformer.setOutputProperty(OutputKeys.ENCODING, encoding);
      xformer.transform(source, new StreamResult(outStream));

      return outStream.toString();
    } catch (Exception e) {
      throw new UtilException("Trans xml document to string error!", e);
    }
  }
View Full Code Here

TOP

Related Classes of com.xiaoleilu.hutool.exceptions.UtilException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.