Package edu.sc.seis.seisFile.seedlink
Class SeedlinkReader
- java.lang.Object
-
- edu.sc.seis.seisFile.seedlink.SeedlinkReader
-
public class SeedlinkReader extends java.lang.ObjectBroke up the 'next' method into 'hasNext' and 'readPacket'. Added 'getInfoString' methods to support getting the SeedLink information string. Added 'select' and 'startData' methods to support start and end time.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDATA_COMMANDstatic java.lang.StringDATA_TYPEstatic java.lang.StringDEFAULT_HOSTstatic intDEFAULT_PORTstatic intDEFAULT_TIMEOUT_SECONDstatic java.lang.StringEMPTYstatic java.lang.StringINFO_ALLstatic java.lang.StringINFO_CAPABILITIESstatic java.lang.StringINFO_CONNECTIONSstatic java.lang.StringINFO_GAPSstatic java.lang.StringINFO_IDstatic java.lang.StringINFO_STATIONSstatic java.lang.StringINFO_STREAMSstatic java.lang.StringTIME_COMMAND
-
Constructor Summary
Constructors Constructor Description SeedlinkReader()default of IRIS DMCSeedlinkReader(java.lang.String host)uses the default port of 18000SeedlinkReader(java.lang.String host, int port)SeedlinkReader(java.lang.String host, int port, int timeoutSeconds)SeedlinkReader(java.lang.String host, int port, int timeoutSeconds, boolean verbose)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanavailable()true if there is enough data in the instream to possibly read a data record.intavailableBytes()Returns available() from the underlying InputStream, in bytesvoidclose()voidendHandshake()java.lang.StringgetHost()java.lang.StringgetInfoString()Get the SeedLink information string for streams.java.lang.StringgetInfoString(java.lang.String infoType)Get the SeedLink information string.java.lang.StringgetInfoString(java.lang.String infoType, boolean addNewlines)Get the SeedLink information string.intgetPort()java.io.PrintWritergetVerboseWriter()booleanhasNext()Determine if a packet may be available.voidinfo(java.lang.String level)send an INFO command.protected voidinternalSendCmd(java.lang.String cmd)booleanisConnected()booleanisVerbose()SeedlinkPacketnext()Get the next packet.protected java.lang.StringreadLine()SeedlinkPacketreadPacket()Read the next packet.voidreconnect()voidselect(java.lang.String network, java.lang.String station, java.lang.String location, java.lang.String channel)Select the stream.voidselect(java.lang.String network, java.lang.String station, java.lang.String location, java.lang.String channel, java.lang.String type)Select the stream.voidsendCmd(java.lang.String cmd)Sends a SeedLink modifier command, generally should be limited tojava.lang.String[]sendHello()voidsetVerbose(boolean verbose)voidsetVerboseWriter(java.io.PrintWriter verboseWriter)voidstartData()Start the data transfer.voidstartData(java.lang.String start, java.lang.String end)Start the data transfer.voidstartData(java.time.Instant start, java.time.Instant end)Start the data transfer.
-
-
-
Field Detail
-
EMPTY
public static final java.lang.String EMPTY
- See Also:
- Constant Field Values
-
DATA_TYPE
public static final java.lang.String DATA_TYPE
- See Also:
- Constant Field Values
-
DATA_COMMAND
public static final java.lang.String DATA_COMMAND
- See Also:
- Constant Field Values
-
TIME_COMMAND
public static final java.lang.String TIME_COMMAND
- See Also:
- Constant Field Values
-
DEFAULT_HOST
public static final java.lang.String DEFAULT_HOST
- See Also:
- Constant Field Values
-
DEFAULT_PORT
public static final int DEFAULT_PORT
- See Also:
- Constant Field Values
-
DEFAULT_TIMEOUT_SECOND
public static final int DEFAULT_TIMEOUT_SECOND
- See Also:
- Constant Field Values
-
INFO_ID
public static final java.lang.String INFO_ID
- See Also:
- Constant Field Values
-
INFO_CAPABILITIES
public static final java.lang.String INFO_CAPABILITIES
- See Also:
- Constant Field Values
-
INFO_STATIONS
public static final java.lang.String INFO_STATIONS
- See Also:
- Constant Field Values
-
INFO_STREAMS
public static final java.lang.String INFO_STREAMS
- See Also:
- Constant Field Values
-
INFO_GAPS
public static final java.lang.String INFO_GAPS
- See Also:
- Constant Field Values
-
INFO_CONNECTIONS
public static final java.lang.String INFO_CONNECTIONS
- See Also:
- Constant Field Values
-
INFO_ALL
public static final java.lang.String INFO_ALL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SeedlinkReader
public SeedlinkReader() throws java.net.UnknownHostException, java.io.IOExceptiondefault of IRIS DMC- Throws:
java.net.UnknownHostExceptionjava.io.IOException
-
SeedlinkReader
public SeedlinkReader(java.lang.String host) throws java.net.UnknownHostException, java.io.IOExceptionuses the default port of 18000- Throws:
java.net.UnknownHostExceptionjava.io.IOException
-
SeedlinkReader
public SeedlinkReader(java.lang.String host, int port) throws java.net.UnknownHostException, java.io.IOException- Throws:
java.net.UnknownHostExceptionjava.io.IOException
-
SeedlinkReader
public SeedlinkReader(java.lang.String host, int port, int timeoutSeconds) throws java.net.UnknownHostException, java.io.IOException- Throws:
java.net.UnknownHostExceptionjava.io.IOException
-
SeedlinkReader
public SeedlinkReader(java.lang.String host, int port, int timeoutSeconds, boolean verbose) throws java.net.UnknownHostException, java.io.IOException- Throws:
java.net.UnknownHostExceptionjava.io.IOException
-
-
Method Detail
-
hasNext
public boolean hasNext() throws java.io.IOExceptionDetermine if a packet may be available. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Returns:
- true if a packet may be available, false if end was received.
- Throws:
java.io.IOException- if an I/O Exception occurs.- See Also:
readPacket()
-
available
public boolean available() throws java.io.IOExceptiontrue if there is enough data in the instream to possibly read a data record. This should not block, unlike hasNext() and next().- Throws:
java.io.IOException
-
availableBytes
public int availableBytes() throws java.io.IOExceptionReturns available() from the underlying InputStream, in bytes- Throws:
java.io.IOException
-
getInfoString
public java.lang.String getInfoString() throws java.io.IOException, SeedlinkException, SeedFormatExceptionGet the SeedLink information string for streams.- Returns:
- the SeedLink information string.
- Throws:
java.io.IOException- if an I/O Exception occurs.SeedlinkException- if no packets or there is an error creating the packet.SeedFormatException- if there is an error with the SEED format.
-
getInfoString
public java.lang.String getInfoString(java.lang.String infoType) throws java.io.IOException, SeedlinkException, SeedFormatExceptionGet the SeedLink information string.- Parameters:
infoType- the information type.- Returns:
- the SeedLink information string.
- Throws:
java.io.IOException- if an I/O Exception occurs.SeedlinkException- if no packets or there is an error creating the packet.SeedFormatException- if there is an error with the SEED format.
-
getInfoString
public java.lang.String getInfoString(java.lang.String infoType, boolean addNewlines) throws java.io.IOException, SeedlinkException, SeedFormatExceptionGet the SeedLink information string.- Parameters:
infoType- the information type.addNewlines- true to add newlines to support XML parsing, false otherwise.- Returns:
- the SeedLink information string.
- Throws:
java.io.IOException- if an I/O Exception occurs.SeedlinkException- if no packets or there is an error creating the packet.SeedFormatException- if there is an error with the SEED format.
-
next
public SeedlinkPacket next() throws java.io.IOException, SeedlinkException
Get the next packet. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Returns:
- the packet or null if none.
- Throws:
java.io.IOException- if an I/O Exception occurs.SeedlinkException- if no packets or there is an error creating the packet.- See Also:
hasNext(),readPacket()
-
readPacket
public SeedlinkPacket readPacket() throws java.io.IOException, SeedlinkException
Read the next packet. This method should be called after calling the 'hasNext' method. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Returns:
- the next packet.
- Throws:
java.io.IOException- if an I/O Exception occurs.SeedlinkException- if there is an error creating the packet.- See Also:
hasNext()
-
info
public void info(java.lang.String level) throws java.io.IOExceptionsend an INFO command. The resulting packets can be retrieved with calls to next(), although it seems there is no good way to determine how many packets will be returned or when they have all arrived without parsing the xml. This appears to be a shortcoming of the seedlink protocol. INFO requests should probably not be sent after the end of the handshake as real data packets may arrive causing confusion.- Throws:
java.io.IOException
-
endHandshake
public void endHandshake() throws java.io.IOException- Throws:
java.io.IOException
-
close
public void close()
-
isConnected
public boolean isConnected()
-
reconnect
public void reconnect() throws java.io.IOException, SeedlinkException- Throws:
java.io.IOExceptionSeedlinkException
-
sendHello
public java.lang.String[] sendHello() throws java.io.IOException, SeedlinkException- Throws:
java.io.IOExceptionSeedlinkException
-
readLine
protected java.lang.String readLine() throws java.io.IOException, SeedlinkException- Throws:
java.io.IOExceptionSeedlinkException
-
sendCmd
public void sendCmd(java.lang.String cmd) throws java.io.IOException, SeedlinkExceptionSends a SeedLink modifier command, generally should be limited to- Parameters:
cmd- the command. STATION, SELECT FETCH, DATA and TIME.- Throws:
SeedlinkException- if a SeedLink error occurs.java.io.IOException- if an I/O Exception occurs.
-
select
public void select(java.lang.String network, java.lang.String station, java.lang.String location, java.lang.String channel) throws SeedlinkException, java.io.IOExceptionSelect the stream.- Parameters:
network- the network.station- the station.location- the location or empty if none.channel- the channel.- Throws:
SeedlinkException- if a SeedLink error occurs.java.io.IOException- if an I/O Exception occurs.
-
select
public void select(java.lang.String network, java.lang.String station, java.lang.String location, java.lang.String channel, java.lang.String type) throws SeedlinkException, java.io.IOExceptionSelect the stream.- Parameters:
network- the network.station- the station.location- the location or empty if none.channel- the channel.type- the data type.- Throws:
SeedlinkExceptionjava.io.IOException
-
startData
public void startData() throws SeedlinkException, java.io.IOExceptionStart the data transfer.- Throws:
SeedlinkException- if a SeedLink error occurs.java.io.IOException- if an I/O Exception occurs.
-
startData
public void startData(java.time.Instant start, java.time.Instant end) throws SeedlinkException, java.io.IOExceptionStart the data transfer. Note the DMC only goes back 48 hours. The start and end time format is year,month,day,hour,minute,second, e.g. '2002,08,05,14,00'.- Parameters:
start- the start time or null if none.end- the end time or null if none (ignored if no start time.)- Throws:
SeedlinkException- if a SeedLink error occurs.java.io.IOException- if an I/O Exception occurs.
-
startData
public void startData(java.lang.String start, java.lang.String end) throws SeedlinkException, java.io.IOExceptionStart the data transfer. Note the DMC only goes back 48 hours. The start and end time format is year,month,day,hour,minute,second, e.g. '2002,08,05,14,00'.- Parameters:
start- the start time or empty string if none.end- the end time or empty string if none (ignored if no start time.)- Throws:
SeedlinkException- if a SeedLink error occurs.java.io.IOException- if an I/O Exception occurs.
-
internalSendCmd
protected void internalSendCmd(java.lang.String cmd) throws java.io.IOException, SeedlinkException- Throws:
java.io.IOExceptionSeedlinkException
-
isVerbose
public boolean isVerbose()
-
setVerbose
public void setVerbose(boolean verbose)
-
getVerboseWriter
public java.io.PrintWriter getVerboseWriter()
-
setVerboseWriter
public void setVerboseWriter(java.io.PrintWriter verboseWriter)
-
getHost
public java.lang.String getHost()
-
getPort
public int getPort()
-
-