@@ -49,16 +49,24 @@ static void parse(final Readable readable, final ParseListener listener)
4949 {
5050 throw new IllegalArgumentException ("readable must not be null" );
5151 }
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
5554 {
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 );
5866 }
5967 if (lineProcessor .getState () != State .DESCRIPTION )
6068 {
61- throw new IOException ("truncated sequence" ); // at line " + lineNumber );
69+ throw new IOException ("truncated sequence at line " + lineProcessor . getLineNumber () );
6270 }
6371 }
6472
@@ -70,6 +78,9 @@ private static class FastqParserLineProcessor implements LineProcessor<Object>
7078 /** Parser state. */
7179 private State state = State .DESCRIPTION ;
7280
81+ /** Line number. */
82+ private long lineNumber = 0 ;
83+
7384 /** Sequence length. */
7485 private int sequenceLength = 0 ;
7586
@@ -115,6 +126,16 @@ private void setState(final State state)
115126 this .state = state ;
116127 }
117128
129+ /**
130+ * Return the line number.
131+ *
132+ * @return the line number
133+ */
134+ private long getLineNumber ()
135+ {
136+ return lineNumber ;
137+ }
138+
118139 @ Override
119140 public Object getResult ()
120141 {
@@ -124,6 +145,8 @@ public Object getResult()
124145 @ Override
125146 public boolean processLine (final String line ) throws IOException
126147 {
148+ lineNumber ++;
149+
127150 String sequence = null ;
128151 String quality = null ;
129152 switch (state )
0 commit comments