Class CharactersView

java.lang.Object
org.apache.sis.internal.storage.esri.CharactersView
All Implemented Interfaces:
CharSequence

final class CharactersView extends Object implements 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

    Fields
    Modifier and Type
    Field
    Description
    private 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
    Whether array is the array backing the buffer.
    (package private) final ChannelDataInput
    The object to use for reading data, or null if unavailable.
    private static final char
    The space character used as sample value separator.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new sequence of characters.
  • Method Summary

    Modifier and Type
    Method
    Description
    char
    charAt(int index)
    Returns the bytes at the given index, converted to a character.
    int
    Returns the number of bytes in the buffer.
    private int
    Reads the next byte as an unsigned value.
    (package private) final Map<String,String>
    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.
    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 SPACE
      The space character used as sample value separator.
      See Also:
    • input

      final ChannelDataInput input
      The object to use for reading data, or null if unavailable. This is null during probe operation. Shall never be null when this instance is the AsciiGridStore.input instance.
    • buffer

      private final ByteBuffer buffer
      The buffer of bytes to wrap. This is the same reference as ChannelData.buffer, copied here because frequently used.
    • array

      private final byte[] array
      The buffer array if the buffer is allocated on the heap, or a temporary array of arbitrary length otherwise.
    • direct

      private final boolean direct
      Whether array is the array backing the buffer. If true, then we do not need some copy operations.
  • Constructor Details

    • CharactersView

      CharactersView(ChannelDataInput input, ByteBuffer buffer)
      Creates a new sequence of characters.
      Parameters:
      input - the source of bytes, or null if unavailable.
      buffer - input.buffer or a standalone buffer if input is null.
  • Method Details

    • length

      public int length()
      Returns the number of bytes in the buffer.
      Specified by:
      length in interface CharSequence
    • charAt

      public char charAt(int index)
      Returns the bytes at the given index, converted to a character.
      Specified by:
      charAt in interface CharSequence
    • readHeader

      final Map<String,String> readHeader() throws IOException, DataStoreContentException
      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

      private int readByte() throws IOException
      Reads the next byte as an unsigned value.
      Throws:
      IOException
    • skipLine

      private boolean skipLine(boolean stopAtToken) throws IOException
      Skips all character until the end of line. This is used for skipping a comment line in the header. This method can be invoked after readToken().
      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

      final String readToken() throws IOException, DataStoreContentException
      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

      public String subSequence(int start, int end)
      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 interface CharSequence
      Parameters:
      start - the start index, inclusive.
      end - the end index, exclusive.
      Returns:
      the specified subsequence
    • toString

      public String 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 interface CharSequence
      Overrides:
      toString in class Object