Class FirstKeywordPeek

java.lang.Object
org.apache.sis.internal.storage.wkt.FirstKeywordPeek
Direct Known Subclasses:
LandsatStoreProvider.Peek, StoreProvider.Peek, StoreProvider.Peek

public abstract class FirstKeywordPeek extends Object
Inspects the type of a text file based on the first keyword.
Since:
0.8
Version:
1.2
  • Field Details

  • Constructor Details

    • FirstKeywordPeek

      public FirstKeywordPeek(int maxLength)
      Creates a new provider.
      Parameters:
      maxLength - length of the longest keyword.
  • Method Details

    • getAuxiliaryPath

      protected Path getAuxiliaryPath(StorageConnector connector) throws DataStoreException
      If the data to read is not provided by the connector by rather by some auxiliary file relative to the connector, returns the path to that auxiliary file. The default implementation returns null.
      Parameters:
      connector - the connector from which to derive the path to auxiliary file to test.
      Returns:
      path to the auxiliary file to test, or null if it does not exist.
      Throws:
      DataStoreException - if an error occurred while determining the auxiliary file.
      Since:
      1.1
    • nextAfterSpaces

      private static int nextAfterSpaces(ByteBuffer buffer, Reader reader) throws IOException
      Returns the next character which is not a white space, or -1 if the end of stream is reached. Exactly one of buffer and reader shall be non-null.
      Throws:
      IOException
    • toEndOfLine

      private static void toEndOfLine(ByteBuffer buffer, Reader reader) throws IOException
      Moves the buffer or stream until the character after the next end of line character.
      Throws:
      IOException
    • isKeywordChar

      protected int isKeywordChar(int c)
      Returns true if the given character is valid for a keyword.
      Parameters:
      c - the character to test.
      Returns:
      ACCEPT if the given character should be accepted, REJECT if the character is not valid for the keyword, or IGNORE if the character should be accepted but not stored.
    • probeContent

      public final ProbeResult probeContent(DataStoreProvider provider, StorageConnector connector) throws DataStoreException
      Returns ProbeResult.SUPPORTED if the given storage appears to begin with an expected keyword. Returning SUPPORTED from this method does not guarantee that reading or writing will succeed, only that there appears to be a reasonable chance of success based on a brief inspection of the storage header.
      Parameters:
      provider - the data store provider which is performing the probe operation.
      connector - information about the storage (URL, stream, etc).
      Returns:
      ProbeResult.SUPPORTED if the given storage seems to be readable.
      Throws:
      DataStoreException - if an I/O error occurred.
    • probeContent

      public final ProbeResult probeContent(Path file) throws DataStoreException
      Returns ProbeResult.SUPPORTED if the content of given file begins with an expected keyword. This method can be invoked as an alternative to
      invalid reference
      #probeContent(StorageConnector)
      when the file to test is not the specified storage, but some auxiliary file.
      Parameters:
      file - the file to partially read.
      Returns:
      ProbeResult.SUPPORTED if the given file seems to be readable.
      Throws:
      DataStoreException - if an I/O error occurred.
      Since:
      1.1
      See Also:
    • probeContent

      private ProbeResult probeContent(ByteBuffer buffer, Reader reader) throws IOException
      Tests the first keyword from one of the given inputs. Exactly one of the two arguments shall be non-null.
      Throws:
      IOException
    • isPostKeyword

      protected abstract boolean isPostKeyword(int c)
      Returns true if the given first non-white character after the keyword is one of the expected characters.
      Parameters:
      c - the first non-white character after the keyword, or -1 if we reached the end of stream.
      Returns:
      true if the given character is one of the expected post-keyword characters.
    • forKeyword

      protected abstract ProbeResult forKeyword(char[] keyword, int length)
      Returns the value to be returned by
      invalid reference
      #probeContent(StorageConnector)
      for the given keyword.
      Parameters:
      keyword - the first keyword found in the input. May be null if length is zero.
      length - number of valid characters in keyword.
      Returns:
      ProbeResult.SUPPORTED if the given storage seems to be readable.