1 package org.codehaus.mojo.natives.parser;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import java.io.IOException;
21 import java.io.Reader;
22
23
24
25
26
27
28 public abstract class AbstractParser
29 {
30
31 protected AbstractParser()
32 {
33 }
34
35 protected abstract void addFilename( String filename );
36
37 public abstract AbstractParserState getNewLineState();
38
39 protected void parse( Reader reader )
40 throws IOException
41 {
42 char[] buf = new char[4096];
43 AbstractParserState newLineState = getNewLineState();
44 AbstractParserState state = newLineState;
45 int charsRead = -1;
46
47 do
48 {
49 charsRead = reader.read( buf, 0, buf.length );
50 if ( state == null )
51 {
52 for ( int i = 0; i < charsRead; i++ )
53 {
54 if ( buf[i] == '\n' )
55 {
56 state = newLineState;
57 break;
58 }
59 }
60 }
61
62 if ( state != null )
63 {
64 for ( int i = 0; i < charsRead; i++ )
65 {
66 state = state.consume( buf[i] );
67
68
69
70 if ( state == null )
71 {
72 for ( ; i < charsRead; i++ )
73 {
74 if ( buf[i] == '\n' )
75 {
76 state = newLineState;
77 break;
78 }
79 }
80 }
81 }
82 }
83
84 }
85 while ( charsRead >= 0 );
86 }
87 }