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 ByteBufferThe buffer of bytes to wrap.private final boolean(package private) final ChannelDataInputThe object to use for reading data, ornullif unavailable.private static final charThe space character used as sample value separator. -
Constructor Summary
ConstructorsConstructorDescriptionCharactersView(ChannelDataInput input, ByteBuffer buffer) Creates a new sequence of characters. -
Method Summary
Modifier and TypeMethodDescriptioncharcharAt(int index) Returns the bytes at the given index, converted to a character.intlength()Returns the number of bytes in the buffer.private intreadByte()Reads the next byte as an unsigned value.Read all (key, value) pairs from the header.(package private) final StringSkips leading white spaces, carriage returns or control characters, then reads and returns the next sequence of non-white characters.private booleanskipLine(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, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints
-
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, ornullif unavailable. This is null during probe operation. Shall never be null when this instance is theAsciiGridStore.inputinstance. -
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, ornullif unavailable.buffer-input.bufferor a standalone buffer ifinputis null.
-
-
Method Details
-
length
public int length()Returns the number of bytes in the buffer.- Specified by:
lengthin interfaceCharSequence
-
charAt
public char charAt(int index) Returns the bytes at the given index, converted to a character.- Specified by:
charAtin 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:
subSequencein 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:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-