Class SeedlinkReader

java.lang.Object
edu.sc.seis.seisFile.seedlink.SeedlinkReader

public class SeedlinkReader
extends java.lang.Object
Reader for the seedlink protocol in multistation mode. Protocol documentation can be found at https://www.seiscomp.de/seiscomp3/doc/applications/seedlink.html Note this implementatino assumes multistation mode. It may be possible to use this in single station mode, but this has not been tested.
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String DATA_COMMAND  
    static java.lang.String DATA_TYPE  
    static java.lang.String DEFAULT_HOST  
    static int DEFAULT_PORT  
    static int DEFAULT_TIMEOUT_SECOND  
    static java.lang.String EMPTY  
    static java.lang.String INFO_ALL  
    static java.lang.String INFO_CAPABILITIES  
    static java.lang.String INFO_CONNECTIONS  
    static java.lang.String INFO_GAPS  
    static java.lang.String INFO_ID  
    static java.lang.String INFO_STATIONS  
    static java.lang.String INFO_STREAMS  
    static java.lang.String TIME_COMMAND  
  • Constructor Summary

    Constructors
    Constructor Description
    SeedlinkReader()
    default of IRIS DMC
    SeedlinkReader​(java.lang.String host)
    uses the default port of 18000
    SeedlinkReader​(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

    Modifier and Type Method Description
    boolean available()
    true if there is enough data in the instream to possibly read a data record.
    int availableBytes()
    Returns available() from the underlying InputStream, in bytes
    void close()  
    void endHandshake()  
    java.lang.String getHost()  
    java.lang.String getInfoString()
    Get the SeedLink information string for streams.
    java.lang.String getInfoString​(java.lang.String infoType)
    Get the SeedLink information string.
    java.lang.String getInfoString​(java.lang.String infoType, boolean addNewlines)
    Get the SeedLink information string.
    int getPort()  
    java.io.PrintWriter getVerboseWriter()  
    boolean hasNext()
    Determine if a packet may be available.
    void info​(java.lang.String level)
    send an INFO command.
    protected void internalSendCmd​(java.lang.String cmd)  
    boolean isConnected()  
    boolean isVerbose()  
    SeedlinkPacket next()
    Get the next packet.
    protected java.lang.String readLine()  
    SeedlinkPacket readPacket()
    Read the next packet.
    void reconnect()  
    void select​(java.lang.String network, java.lang.String station, java.lang.String location, java.lang.String channel)
    Select the stream.
    void select​(java.lang.String network, java.lang.String station, java.lang.String location, java.lang.String channel, java.lang.String type)
    Select the stream.
    void sendCmd​(java.lang.String cmd)
    Sends a SeedLink modifier command, generally should be limited to STATION, SELECT, FETCH, DATA and TIME.
    java.lang.String[] sendHello()  
    void setVerbose​(boolean verbose)  
    void setVerboseWriter​(java.io.PrintWriter verboseWriter)  
    void startData()
    Start the data transfer.
    void startData​(java.lang.String start, java.lang.String end)
    Start the data transfer.
    void startData​(java.time.Instant start, java.time.Instant end)
    Start the data transfer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • SeedlinkReader

      public SeedlinkReader() throws java.net.UnknownHostException, java.io.IOException
      default of IRIS DMC
      Throws:
      java.net.UnknownHostException
      java.io.IOException
    • SeedlinkReader

      public SeedlinkReader​(java.lang.String host) throws java.net.UnknownHostException, java.io.IOException
      uses the default port of 18000
      Throws:
      java.net.UnknownHostException
      java.io.IOException
    • SeedlinkReader

      public SeedlinkReader​(java.lang.String host, int port) throws java.net.UnknownHostException, java.io.IOException
      Throws:
      java.net.UnknownHostException
      java.io.IOException
    • SeedlinkReader

      public SeedlinkReader​(java.lang.String host, int port, int timeoutSeconds) throws java.net.UnknownHostException, java.io.IOException
      Throws:
      java.net.UnknownHostException
      java.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.UnknownHostException
      java.io.IOException
  • Method Details

    • hasNext

      public boolean hasNext() throws java.io.IOException
      Determine 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.IOException
      true 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.IOException
      Returns available() from the underlying InputStream, in bytes
      Throws:
      java.io.IOException
    • getInfoString

      public java.lang.String getInfoString() throws java.io.IOException, SeedlinkException, SeedFormatException
      Get 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, SeedFormatException
      Get 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, SeedFormatException
      Get 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.IOException
      send 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.IOException
      SeedlinkException
    • sendHello

      public java.lang.String[] sendHello() throws java.io.IOException, SeedlinkException
      Throws:
      java.io.IOException
      SeedlinkException
    • readLine

      protected java.lang.String readLine() throws java.io.IOException, SeedlinkException
      Throws:
      java.io.IOException
      SeedlinkException
    • sendCmd

      public void sendCmd​(java.lang.String cmd) throws java.io.IOException, SeedlinkException
      Sends a SeedLink modifier command, generally should be limited to STATION, SELECT, FETCH, DATA and TIME.
      Parameters:
      cmd - the command.
      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.IOException
      Select 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.IOException
      Select the stream.
      Parameters:
      network - the network.
      station - the station.
      location - the location or empty if none.
      channel - the channel.
      type - the data type.
      Throws:
      SeedlinkException
      java.io.IOException
    • startData

      public void startData() throws SeedlinkException, java.io.IOException
      Start 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.IOException
      Start 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.IOException
      Start 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.IOException
      SeedlinkException
    • 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()