crotwell / seisFile

A library for reading and writing seismic file formats in java.
GNU Lesser General Public License v3.0
27 stars 20 forks source link

SeedLinkReader Line Ending #20

Closed drammelt closed 3 years ago

drammelt commented 3 years ago

SeedLinkReader expects \r\n ending and throws an exception if the \n does not follow the \r

// next should now be a \n, so just eat it        
next = in.read();        
if (next != '\n') {            
    throw new SeedlinkException("Got \\r but not followed by \\n buf: '"+buf.toString()+"' next: " + next);        
}        
return buf.toString();

We have a server that only outputs the \r and works fine with the tool we have been using until now, slinktool from https://ds.iris.edu/ds/nodes/dmc/software/downloads/slinktool

My expectation is that the parser would end if either a \r or \n is found as this would match all line ending formats and if the \n is missing it is irrelevant. This would also mean the exception is not needed.

So is the \n absolutely necessary to conform with the mseed format?

drammelt commented 3 years ago

From the slinktool changelog

Do not send terminating NULL characters in command strings sent to the server. The protocol stipulates that commands must be terminated with a carriage return (\r) followed by an optional new line (\n). The library now strictly terminates commands with only a carriage return.

crotwell commented 3 years ago

Unfortunately seedlink doesn't have a real specification, so it is hard know how all servers behave, much less to enforce things like this. I can update the code to allow \r, \n or \r\n as line endings.

Fixed in https://github.com/crotwell/seisFile/commit/31839c0334c264a38b834fa8dc77e59fc3062f20

crotwell commented 3 years ago

released in ver 2.0.1