FileDefinitionParser { String nextLine( BufferedReader br ) throws IOException { int c = 0; StringBuilder sb = new StringBuilder(); while(( c = br.read()) != -1 && ((char) c) != '\n' ) { if((char) c != '\r' ) sb.append((char) c); } if( sb.length() > 0 ) this.lastLineEndedWithLineBreak = c != -1; String line = c == -1 && sb.length() == 0 ? null : sb.toString(); this.currentLineNumber ++; return line; } FileDefinitionParser( File relationsFile, boolean ignoreComments ); FileDefinition read();  }
@Test public void testNextLine() throws Exception { FileDefinitionParser parser = new FileDefinitionParser( new File( "whatever" ), true ); Assert.assertEquals( 0, parser.currentLineNumber ); StringBuilder sb = new StringBuilder(); sb.append( "# this is a comment\n" ); sb.append( "\n" ); sb.append( "VM {\n" ); sb.append( "\tinstaller: target; # !!!\n" ); sb.append( "\n" ); sb.append( "}\n" ); sb.append( "\r\n" ); sb.append( "\n" ); BufferedReader br = new BufferedReader( new StringReader( sb.toString())); Assert.assertEquals( "# this is a comment", parser.nextLine( br )); Assert.assertEquals( 1, parser.currentLineNumber ); Assert.assertEquals( "", parser.nextLine( br )); Assert.assertEquals( 2, parser.currentLineNumber ); Assert.assertEquals( "VM {", parser.nextLine( br )); Assert.assertEquals( 3, parser.currentLineNumber ); Assert.assertEquals( "\tinstaller: target; # !!!", parser.nextLine( br )); Assert.assertEquals( 4, parser.currentLineNumber ); Assert.assertEquals( "", parser.nextLine( br )); Assert.assertEquals( 5, parser.currentLineNumber ); Assert.assertEquals( "}", parser.nextLine( br )); Assert.assertEquals( 6, parser.currentLineNumber ); Assert.assertEquals( "", parser.nextLine( br )); Assert.assertEquals( 7, parser.currentLineNumber ); Assert.assertEquals( "", parser.nextLine( br )); Assert.assertEquals( 8, parser.currentLineNumber ); }