* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
*/
package org.onap.clamp.clds.util;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Scanner;
/**
- * Utility methods supporting transforms.
+ * Utility methods supporting resources accesses.
*/
-public class ResourceFileUtil {
+public final class ResourceFileUtil {
/**
- * Disable the ResourceFileUtil constructor.
+ * Private constructor to avoid creating instances of util class.
*/
private ResourceFileUtil() {
-
}
/**
* Return resource as a Stream.
*
- * @param name
* @return resource - resource as stream
*/
public static InputStream getResourceAsStream(String name) {
}
/**
- * Return resource as a Stream.
- *
- * @param name
- * @throws IOException
+ * Return resource as a String.
*/
public static String getResourceAsString(String name) throws IOException {
- InputStream is = getResourceAsStream(name);
- java.util.Scanner scanner = new java.util.Scanner(is);
- java.util.Scanner delimitedScanner = scanner.useDelimiter("\\A");
- String text = delimitedScanner.hasNext() ? delimitedScanner.next() : "";
- delimitedScanner.close();
- scanner.close();
- is.close();
- return text;
+ try (InputStream is = getResourceAsStream(name)) {
+ try (Scanner scanner = new Scanner(is)) {
+ Scanner delimitedScanner = scanner.useDelimiter("\\A");
+ return delimitedScanner.hasNext() ? delimitedScanner.next() : "";
+ }
+ }
}
}