001 package org.cumulus4j.keymanager.cli.resource; 002 003 import java.io.BufferedReader; 004 import java.io.InputStream; 005 import java.io.InputStreamReader; 006 import java.io.UnsupportedEncodingException; 007 008 /** 009 * Helper for accessing resource files. 010 * 011 * @author Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de 012 */ 013 public final class ResourceHelper { 014 015 private ResourceHelper() { } 016 017 public static InputStream openLicenceAsStream() 018 { 019 String resourceName = "LICENCE.txt"; 020 InputStream inputStream = ResourceHelper.class.getResourceAsStream(resourceName); 021 if (inputStream == null) 022 throw new IllegalStateException("Resource \"" + resourceName + "\" could not be found!"); 023 024 return inputStream; 025 } 026 027 public static BufferedReader openLicenceAsBufferedReader() 028 { 029 try { 030 return new BufferedReader(new InputStreamReader(openLicenceAsStream(), "UTF-8")); 031 } catch (UnsupportedEncodingException e) { 032 throw new RuntimeException(e); // should never happen, that "UTF-8" is unsupported! 033 } 034 } 035 }