private Observable < String > loadLogsObservable ( ) { return Observable . fromCallable ( ( ) -> { StringBuilder sb = new StringBuilder ( ) ; Context context = appContextRef . get ( ) ; if ( context != null ) { synchronized ( sharedLock ) { try { File dir = context . getFilesDir ( ) ; String line ; for ( int i = 1 ; i <= maxFiles ; i ++ ) { File file = new File ( dir , name ( i ) ) ; if ( file . exists ( ) ) { inputStream = new FileInputStream ( file ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; while ( ( line = reader . readLine ( ) ) != null ) { sb . append ( line ) . append ( ' ' ) ; } reader . close ( ) ; } } } catch ( Exception e ) { throw Exceptions . propagate ( e ) ; } finally { sharedLock . notifyAll ( ) ; } } } return sb . toString ( ) ; } ) ; }
Gets rx observable that reads the log files and appends to string .