in commons-email2-jakarta/src/main/java/org/apache/commons/mail2/jakarta/resolver/DataSourceClassPathResolver.java [91:124]
public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException {
try {
if (!isCid(resourceLocation) && !isHttpUrl(resourceLocation)) {
final String mimeType = FileTypeMap.getDefaultFileTypeMap().getContentType(resourceLocation);
final String resourceName = getResourceName(resourceLocation);
try (InputStream inputStream = DataSourceClassPathResolver.class.getResourceAsStream(resourceName)) {
if (inputStream == null) {
if (isLenient) {
return null;
}
throw new IOException("The following class path resource was not found : " + resourceLocation);
}
final ByteArrayDataSource ds = new ByteArrayDataSource(inputStream, mimeType);
// EMAIL-125: set the name of the DataSource to the normalized resource URL
// similar to other DataSource implementations, e.g. FileDataSource, URLDataSource
final URL resource = DataSourceClassPathResolver.class.getResource(resourceName);
if (resource != null) {
ds.setName(resource.toString());
} else if (isLenient) {
return null;
} else {
throw new IOException("The following class path resource was not found : " + resourceName);
}
return ds;
}
}
return null;
} catch (final IOException e) {
if (isLenient) {
return null;
}
throw e;
}
}