Class CharactersView
java.lang.Object
org.apache.sis.internal.storage.esri.CharactersView
- All Implemented Interfaces:
CharSequence
Character sequences as a view over a buffer of bytes interpreted as US-ASCII characters.
The character sequence starts always at zero and its length is the buffer limit.
The intent is to allow the use of
Integer.parseInt(CharSequence, int, int, int)
.- Since:
- 1.2
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]
The buffer array if the buffer is allocated on the heap, or a temporary array of arbitrary length otherwise.private final ByteBuffer
The buffer of bytes to wrap.private final boolean
(package private) final ChannelDataInput
The object to use for reading data, ornull
if unavailable.private static final char
The space character used as sample value separator. -
Constructor Summary
ConstructorsConstructorDescriptionCharactersView
(ChannelDataInput input, ByteBuffer buffer) Creates a new sequence of characters. -
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int index) Returns the bytes at the given index, converted to a character.int
length()
Returns the number of bytes in the buffer.private int
readByte()
Reads the next byte as an unsigned value.Read all (key, value) pairs from the header.(package private) final String
Skips leading white spaces, carriage returns or control characters, then reads and returns the next sequence of non-white characters.private boolean
skipLine
(boolean stopAtToken) Skips all character until the end of line.subSequence
(int start, int end) Returns a copy of the buffer content over the given range of bytes.toString()
Returns a string representation of the buffer content.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
SPACE
private static final char SPACEThe space character used as sample value separator.- See Also:
-
input
The object to use for reading data, ornull
if unavailable. This is null during probe operation. Shall never be null when this instance is theAsciiGridStore.input
instance. -
buffer
The buffer of bytes to wrap. This is the same reference asChannelData.buffer
, copied here because frequently used. -
array
private final byte[] arrayThe buffer array if the buffer is allocated on the heap, or a temporary array of arbitrary length otherwise. -
direct
private final boolean direct
-
-
Constructor Details
-
CharactersView
CharactersView(ChannelDataInput input, ByteBuffer buffer) Creates a new sequence of characters.- Parameters:
input
- the source of bytes, ornull
if unavailable.buffer
-input.buffer
or a standalone buffer ifinput
is null.
-
-
Method Details
-
length
public int length()Returns the number of bytes in the buffer.- Specified by:
length
in interfaceCharSequence
-
charAt
public char charAt(int index) Returns the bytes at the given index, converted to a character.- Specified by:
charAt
in interfaceCharSequence
-
readHeader
Read all (key, value) pairs from the header. All keys are converted to upper-case letters. The map may contain null values if a key was declared with no value.- Returns:
- the (key, value) pairs, with keys in upper-case letters.
- Throws:
IOException
- if an error occurred while reading the header.DataStoreContentException
- if a duplicated key is found.
-
readByte
Reads the next byte as an unsigned value.- Throws:
IOException
-
skipLine
Skips all character until the end of line. This is used for skipping a comment line in the header. This method can be invoked afterreadToken()
.- Parameters:
stopAtToken
- whether to stop at the first non-white character.- Returns:
- whether end of line has been reached.
- Throws:
EOFException
- if the channel has reached the end of stream.IOException
- if another kind of error occurred while reading.
-
readToken
Skips leading white spaces, carriage returns or control characters, then reads and returns the next sequence of non-white characters. After this method call, the buffer position is on the first white character after the token.- Returns:
- the next token, never empty and without leading or trailing white spaces.
- Throws:
EOFException
- if the channel has reached the end of stream.IOException
- if another kind of error occurred while reading.DataStoreContentException
- if the content does not seem to comply with ASCII Grid format.
-
subSequence
Returns a copy of the buffer content over the given range of bytes. This method should be invoked only for small ranges (e.g. less than 80 characters). We use it for parsing floating point numbers.- Specified by:
subSequence
in interfaceCharSequence
- Parameters:
start
- the start index, inclusive.end
- the end index, exclusive.- Returns:
- the specified subsequence
-
toString
Returns a string representation of the buffer content. Note that it represents only a truncated view of the file content.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classObject
-