/** * Format a path to ensure that it begins with a '/' character. * * @param path the path to format * @return a correctly formatted path string */ public static String formatPathForOpenStream(final String path) { if (StringUtils.isEmpty(path)) { processException(path); } return path.startsWith("/") ? path : "/" + path; } }
/** * Open the file found at the the specified path under the location of the given * class. * * @param clazz the class location * @param path the path in the class location * @return an input stream representating the requested file * @throws IllegalArgumentException if there was an error opening the stream */ public static InputStream openStream(final Class clazz, final String path) throws IllegalArgumentException { final String checkedPath = formatPathForOpenStream(path); final InputStream resourceAsStream = clazz.getResourceAsStream(checkedPath); return (null != resourceAsStream) ? resourceAsStream : processException(path); }