Class FirstKeywordPeek
java.lang.Object
org.apache.sis.internal.storage.wkt.FirstKeywordPeek
- Direct Known Subclasses:
LandsatStoreProvider.Peek
,StoreProvider.Peek
,StoreProvider.Peek
Inspects the type of a text file based on the first keyword.
- Since:
- 0.8
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
Return values for theisKeywordChar(int)
method.protected static final char
The comment character to ignore.protected static final int
Return values for theisKeywordChar(int)
method.protected final int
Length of the longest keyword.(package private) static final int
The read-ahead limit when reading a text from aReader
.protected static final int
Return values for theisKeywordChar(int)
method. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract ProbeResult
forKeyword
(char[] keyword, int length) Returns the value to be returned byinvalid reference
#probeContent(StorageConnector)
protected Path
getAuxiliaryPath
(StorageConnector connector) 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.protected int
isKeywordChar
(int c) Returnstrue
if the given character is valid for a keyword.protected abstract boolean
isPostKeyword
(int c) Returnstrue
if the given first non-white character after the keyword is one of the expected characters.private static int
nextAfterSpaces
(ByteBuffer buffer, Reader reader) Returns the next character which is not a white space, or -1 if the end of stream is reached.private ProbeResult
probeContent
(ByteBuffer buffer, Reader reader) Tests the first keyword from one of the given inputs.final ProbeResult
probeContent
(Path file) ReturnsProbeResult.SUPPORTED
if the content of given file begins with an expected keyword.final ProbeResult
probeContent
(DataStoreProvider provider, StorageConnector connector) ReturnsProbeResult.SUPPORTED
if the given storage appears to begin with an expected keyword.private static void
toEndOfLine
(ByteBuffer buffer, Reader reader) Moves the buffer or stream until the character after the next end of line character.
-
Field Details
-
REJECT
protected static final int REJECTReturn values for theisKeywordChar(int)
method.- See Also:
-
ACCEPT
protected static final int ACCEPTReturn values for theisKeywordChar(int)
method.- See Also:
-
IGNORE
protected static final int IGNOREReturn values for theisKeywordChar(int)
method.- See Also:
-
READ_AHEAD_LIMIT
static final int READ_AHEAD_LIMITThe read-ahead limit when reading a text from aReader
. Should be no more thanStorageConnector.DEFAULT_BUFFER_SIZE / 2
.- See Also:
-
COMMENT
protected static final char COMMENTThe comment character to ignore.- See Also:
-
maxLength
protected final int maxLengthLength of the longest keyword.
-
-
Constructor Details
-
FirstKeywordPeek
public FirstKeywordPeek(int maxLength) Creates a new provider.- Parameters:
maxLength
- length of the longest keyword.
-
-
Method Details
-
getAuxiliaryPath
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 returnsnull
.- 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
Returns the next character which is not a white space, or -1 if the end of stream is reached. Exactly one ofbuffer
andreader
shall be non-null.- Throws:
IOException
-
toEndOfLine
Moves the buffer or stream until the character after the next end of line character.- Throws:
IOException
-
isKeywordChar
protected int isKeywordChar(int c) Returnstrue
if the given character is valid for a keyword. -
probeContent
public final ProbeResult probeContent(DataStoreProvider provider, StorageConnector connector) throws DataStoreException ReturnsProbeResult.SUPPORTED
if the given storage appears to begin with an expected keyword. ReturningSUPPORTED
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
ReturnsProbeResult.SUPPORTED
if the content of given file begins with an expected keyword. This method can be invoked as an alternative toinvalid reference
#probeContent(StorageConnector)
- 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
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) Returnstrue
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
Returns the value to be returned byinvalid reference
#probeContent(StorageConnector)
- Parameters:
keyword
- the first keyword found in the input. May benull
iflength
is zero.length
- number of valid characters inkeyword
.- Returns:
ProbeResult.SUPPORTED
if the given storage seems to be readable.
-