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();
}
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);
}
}
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);
}
}
Aggregations