public String retrieveData ( String baseData , String type ) { String result ; InputStream stream = getClass ( ) . getClassLoader ( ) . getResourceAsStream ( baseData ) ; Writer writer = new StringWriter ( ) ; char [ ] buffer = new char [ 1024 ] ; Reader reader ; if ( stream == null ) { this . getLogger ( ) . error ( "File does not exist: {}" , baseData ) ; return "ERR! File not found: " + baseData ; } try { reader = new BufferedReader ( new InputStreamReader ( stream , "UTF-8" ) ) ; int n ; while ( ( n = reader . read ( buffer ) ) != - 1 ) { writer . write ( buffer , 0 , n ) ; } } catch ( Exception readerexception ) { this . getLogger ( ) . error ( readerexception . getMessage ( ) ) ; } finally { try { stream . close ( ) ; } catch ( Exception closeException ) { this . getLogger ( ) . error ( closeException . getMessage ( ) ) ; } } String text = writer . toString ( ) ; String std = text . replace ( "\r" , "" ) . replace ( "\n" , "" ) ; // make sure we have unix style text regardless of the input if ( "json" . equals ( type ) ) { result = JsonValue . readHjson ( std ) . asObject ( ) . toString ( ) ; } else { result = std ; } return result ; }
Returns the information contained in file passed as parameter