Search in sources :

Example 1 with WrapException

use of org.seasar.doma.internal.WrapException in project doma by domaframework.

the class IOUtil method readAsString.

public static String readAsString(InputStream inputStream) throws WrapException {
    assertNotNull(inputStream);
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Constants.UTF_8));
    StringBuilder buf = new StringBuilder(200);
    try {
        CharBuffer c = CharBuffer.allocate(BUF_SIZE);
        while (reader.read(c) > -1) {
            c.flip();
            buf.append(c);
            c.clear();
        }
    } catch (IOException e) {
        throw new WrapException(e);
    } finally {
        IOUtil.close(reader);
    }
    return buf.toString();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) CharBuffer(java.nio.CharBuffer) IOException(java.io.IOException) WrapException(org.seasar.doma.internal.WrapException)

Example 2 with WrapException

use of org.seasar.doma.internal.WrapException in project doma by domaframework.

the class IOUtil method readAsString.

public static String readAsString(File file) throws WrapException {
    assertNotNull(file);
    InputStream inputStream = null;
    try {
        inputStream = new FileInputStream(file);
        return readAsString(inputStream);
    } catch (FileNotFoundException e) {
        throw new WrapException(e);
    } finally {
        IOUtil.close(inputStream);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) WrapException(org.seasar.doma.internal.WrapException) FileInputStream(java.io.FileInputStream)

Example 3 with WrapException

use of org.seasar.doma.internal.WrapException in project doma by domaframework.

the class DomainTypeFactory method getDomainType.

/**
 * Creates the domain description with {@link ClassHelper}.
 *
 * @param <BASIC> the basic type
 * @param <DOMAIN> the domain type
 * @param domainClass the domain class
 * @param classHelper the class helper
 * @return the domain description
 * @throws DomaNullPointerException if any arguments are {@code null}
 * @throws DomaIllegalArgumentException if the domain class is not annotated with {@link Domain}
 * @throws DomainTypeNotFoundException if the domain description is not found
 */
public static <BASIC, DOMAIN> DomainType<BASIC, DOMAIN> getDomainType(Class<DOMAIN> domainClass, ClassHelper classHelper) {
    if (domainClass == null) {
        throw new DomaNullPointerException("domainClass");
    }
    if (classHelper == null) {
        throw new DomaNullPointerException("classHelper");
    }
    if (!domainClass.isAnnotationPresent(Domain.class) && !domainClass.isAnnotationPresent(DataType.class)) {
        throw new DomaIllegalArgumentException("domainClass", Message.DOMA2205.getMessage(domainClass.getName()));
    }
    String domainTypeClassName = ClassNames.newDomainTypeClassName(domainClass.getName()).toString();
    try {
        Class<DOMAIN> clazz = classHelper.forName(domainTypeClassName);
        Method method = ClassUtil.getMethod(clazz, "getSingletonInternal");
        return MethodUtil.invoke(method, null);
    } catch (WrapException e) {
        throw new DomainTypeNotFoundException(e.getCause(), domainClass.getName(), domainTypeClassName);
    } catch (Exception e) {
        throw new DomainTypeNotFoundException(e, domainClass.getName(), domainTypeClassName);
    }
}
Also used : DomaNullPointerException(org.seasar.doma.DomaNullPointerException) Method(java.lang.reflect.Method) WrapException(org.seasar.doma.internal.WrapException) WrapException(org.seasar.doma.internal.WrapException) DomaIllegalArgumentException(org.seasar.doma.DomaIllegalArgumentException) DomaNullPointerException(org.seasar.doma.DomaNullPointerException) DomaIllegalArgumentException(org.seasar.doma.DomaIllegalArgumentException)

Aggregations

WrapException (org.seasar.doma.internal.WrapException)3 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Method (java.lang.reflect.Method)1 CharBuffer (java.nio.CharBuffer)1 DomaIllegalArgumentException (org.seasar.doma.DomaIllegalArgumentException)1 DomaNullPointerException (org.seasar.doma.DomaNullPointerException)1