public DataSource resolve()

in src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java [83:116]


    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 is = DataSourceClassPathResolver.class.getResourceAsStream(resourceName)){
                    if (is == null) {
                        if (isLenient)
                        {
                            return null;
                        }
                        throw new IOException("The following class path resource was not found : " + resourceLocation);
                    }
                    final ByteArrayDataSource ds = new ByteArrayDataSource(is, mimeType);
                    // EMAIL-125: set the name of the DataSource to the normalized resource URL
                    // similar to other DataSource implementations, e.g. FileDataSource, URLDataSource
                    ds.setName(DataSourceClassPathResolver.class.getResource(resourceName).toString());
                    return ds;
                }
            }
            return null;
        }
        catch (final IOException e)
        {
            if (isLenient)
            {
                return null;
            }
            throw e;
        }
    }