@@ -49,16 +49,24 @@ static void parse(final Readable readable, final ParseListener listener)
49
49
{
50
50
throw new IllegalArgumentException ("readable must not be null" );
51
51
}
52
- FastqParserLineProcessor lineProcessor = new FastqParserLineProcessor (listener );
53
- CharStreams .readLines (readable , lineProcessor );
54
- if (lineProcessor .getState () == State .COMPLETE )
52
+ final FastqParserLineProcessor lineProcessor = new FastqParserLineProcessor (listener );
53
+ try
55
54
{
56
- listener .complete ();
57
- lineProcessor .setState (State .DESCRIPTION );
55
+ CharStreams .readLines (readable , lineProcessor );
56
+
57
+ if (lineProcessor .getState () == State .COMPLETE )
58
+ {
59
+ listener .complete ();
60
+ lineProcessor .setState (State .DESCRIPTION );
61
+ }
62
+ }
63
+ catch (IOException e )
64
+ {
65
+ throw new IOException ("parse error at line " + lineProcessor .getLineNumber () + ", state " + lineProcessor .getState (), e );
58
66
}
59
67
if (lineProcessor .getState () != State .DESCRIPTION )
60
68
{
61
- throw new IOException ("truncated sequence" ); // at line " + lineNumber );
69
+ throw new IOException ("truncated sequence at line " + lineProcessor . getLineNumber () );
62
70
}
63
71
}
64
72
@@ -70,6 +78,9 @@ private static class FastqParserLineProcessor implements LineProcessor<Object>
70
78
/** Parser state. */
71
79
private State state = State .DESCRIPTION ;
72
80
81
+ /** Line number. */
82
+ private long lineNumber = 0 ;
83
+
73
84
/** Sequence length. */
74
85
private int sequenceLength = 0 ;
75
86
@@ -115,6 +126,16 @@ private void setState(final State state)
115
126
this .state = state ;
116
127
}
117
128
129
+ /**
130
+ * Return the line number.
131
+ *
132
+ * @return the line number
133
+ */
134
+ private long getLineNumber ()
135
+ {
136
+ return lineNumber ;
137
+ }
138
+
118
139
@ Override
119
140
public Object getResult ()
120
141
{
@@ -124,6 +145,8 @@ public Object getResult()
124
145
@ Override
125
146
public boolean processLine (final String line ) throws IOException
126
147
{
148
+ lineNumber ++;
149
+
127
150
String sequence = null ;
128
151
String quality = null ;
129
152
switch (state )
0 commit comments