public static String make512Safe ( StringBuffer input , String newline ) { StringBuilder result = new StringBuilder ( ) ; String content = input . toString ( ) ; String rest = content ; while ( ! rest . isEmpty ( ) ) { if ( rest . contains ( "\n" ) ) { String line = rest . substring ( 0 , rest . indexOf ( "\n" ) ) ; rest = rest . substring ( rest . indexOf ( "\n" ) + 1 ) ; if ( line . length ( ) > 1 && line . charAt ( line . length ( ) - 1 ) == ' ' ) line = line . substring ( 0 , line . length ( ) - 1 ) ; append512Safe ( line , result , newline ) ; } else { append512Safe ( rest , result , newline ) ; break ; } } return result . toString ( ) ; }
Return a string that ensures that no line is longer then 512 characters and lines are broken according to manifest specification .