/** * Read the lines from the content of the resource file at the given path on the classpath. * * @param resourcePath the logical path to the classpath, file, or URL resource * @param classLoader the classloader that should be used to load the resource as a stream; may be null * @param clazz the class that should be used to load the resource as a stream; may be null * @param lineProcessor the function that this method calls for each line read from the supplied stream; may not be null * @throws IOException if an I/O error occurs */ public static void readLines(String resourcePath, ClassLoader classLoader, Class<?> clazz, Consumer<String> lineProcessor) throws IOException { try (InputStream stream = IoUtil.getResourceAsStream(resourcePath, classLoader, clazz, null, null)) { IoUtil.readLines(stream, lineProcessor); } }
/** * Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied * path. * * @param path the path to the file containing the configuration properties; may not be null * @param classLoader the class loader to use; may be null * @param logger the function that will be called with status updates; may be null * @return the configuration; never null but possibly empty * @throws IOException if there is an error reading the stream */ public static Configuration load(String path, ClassLoader classLoader, Consumer<String> logger) throws IOException { try (InputStream stream = IoUtil.getResourceAsStream(path, classLoader, null, null, logger)) { Properties props = new Properties(); if (stream != null) { props.load(stream); } return from(props); } }
/** * Read the lines from the content of the resource file at the given path on the classpath. * * @param resourcePath the logical path to the classpath, file, or URL resource * @param classLoader the classloader that should be used to load the resource as a stream; may be null * @param clazz the class that should be used to load the resource as a stream; may be null * @param lineProcessor the function that this method calls for each line read from the supplied stream; may not be null * @throws IOException if an I/O error occurs */ public static void readLines(String resourcePath, ClassLoader classLoader, Class<?> clazz, Consumer<String> lineProcessor) throws IOException { try (InputStream stream = IoUtil.getResourceAsStream(resourcePath, classLoader, clazz, null, null)) { IoUtil.readLines(stream, lineProcessor); } }
/** * Obtain a configuration instance by loading the Properties from a file on the file system or classpath given by the supplied * path. * * @param path the path to the file containing the configuration properties; may not be null * @param classLoader the class loader to use; may be null * @param logger the function that will be called with status updates; may be null * @return the configuration; never null but possibly empty * @throws IOException if there is an error reading the stream */ public static Configuration load(String path, ClassLoader classLoader, Consumer<String> logger) throws IOException { try (InputStream stream = IoUtil.getResourceAsStream(path, classLoader, null, null, logger)) { Properties props = new Properties(); if (stream != null) { props.load(stream); } return from(props); } }