public static String convertToHocon ( File props ) throws IOException { StringBuilder output = new StringBuilder ( ) ; List < String > lines = FileUtils . readLines ( props ) ; boolean readingValue = false ; for ( String line : lines ) { if ( isComment ( line ) ) { // Comment output . append ( "#" ) . append ( line . trim ( ) . substring ( 1 ) ) . append ( "\n" ) ; continue ; } if ( line . trim ( ) . isEmpty ( ) ) { if ( ! readingValue ) { output . append ( "\n" ) ; } continue ; } if ( ! readingValue ) { int position = getKeyValueSeparatorPosition ( line ) ; if ( position != 0 ) { String key = line . substring ( 0 , position ) . trim ( ) ; int vPosition = getValueStartPosition ( line , position ) ; String value ; if ( vPosition == - 1 ) { // No value value = "" ; } else { value = fixValue ( line . substring ( vPosition ) . trim ( ) ) ; } output . append ( fixKey ( key ) ) . append ( "=" ) ; if ( value . endsWith ( "\\" ) ) { // Multiline readingValue = true ; output . append ( "\"" ) ; output . append ( value . substring ( 0 , value . length ( ) - 1 ) ) ; } else { if ( vPosition == - 1 ) { output . append ( "\"\"" ) ; } else { output . append ( fixSingleLineValue ( line . substring ( vPosition ) ) . trim ( ) ) . append ( "\n" ) ; } readingValue = false ; } } else { throw new IllegalStateException ( "No key-value separator found in " + line ) ; } } else { String value = line . trim ( ) ; if ( value . endsWith ( "\\" ) ) { // Multiline readingValue = true ; output . append ( fixValue ( value . substring ( 0 , value . length ( ) - 1 ) ) ) ; } else { output . append ( fixValue ( value ) ) . append ( "\"\n" ) ; readingValue = false ; } } } return output . toString ( ) ; }
Generates the hocon string resulting from the conversion of the given properties file .