Class AbstractCommonShapeFileReader<E>

    • Field Detail

      • BLOCK_SIZE

        protected static final int BLOCK_SIZE
        Size of a block of data in the buffer, when the seek feature was disable.
        See Also:
        Constant Field Values
      • fileSize

        protected int fileSize
        Size in bytes of the input stream.
      • minx

        protected double minx
        Bounding box in the file header.
      • miny

        protected double miny
        Bounding box in the file header.
      • minz

        protected double minz
        Bounding box in the file header.
      • minm

        protected double minm
        Bounding box in the file header.
      • maxx

        protected double maxx
        Bounding box in the file header.
      • maxy

        protected double maxy
        Bounding box in the file header.
      • maxz

        protected double maxz
        Bounding box in the file header.
      • maxm

        protected double maxm
        Bounding box in the file header.
      • expectedShapeType

        protected ShapeElementType expectedShapeType
        Is the type of element stored inside the shape file.
    • Constructor Detail

      • AbstractCommonShapeFileReader

        public AbstractCommonShapeFileReader​(ReadableByteChannel inputStream)
        Constructor.
        Parameters:
        inputStream - is the stream to read
      • AbstractCommonShapeFileReader

        public AbstractCommonShapeFileReader​(InputStream inputStream)
        Constructor.
        Parameters:
        inputStream - is the stream to read
      • AbstractCommonShapeFileReader

        public AbstractCommonShapeFileReader​(File file)
                                      throws IOException
        Constructor.
        Parameters:
        file - is the file to read
        Throws:
        IOException - if cannot read.
      • AbstractCommonShapeFileReader

        public AbstractCommonShapeFileReader​(URL file)
                                      throws IOException
        Constructor.
        Parameters:
        file - is the file to read
        Throws:
        IOException - if cannot read.
    • Method Detail

      • isHeaderRead

        @Pure
        protected boolean isHeaderRead()
        Replies if the header was read.
        Returns:
        true if the header was read, otherwise false
      • getTaskProgression

        @Pure
        public Progression getTaskProgression()
        Replies the task progression.
        Returns:
        the task progression object associated to this writer, or null
      • setTaskProgression

        public void setTaskProgression​(Progression progressBar)
        Set the task progression associated to this writer.
        Parameters:
        progressBar - is the task progression object associated to this writer, or null
      • getFileSize

        public int getFileSize()
                        throws IOException
        Replies the total size of the Shape file.
        Returns:
        the size of the shape file in bytes
        Throws:
        IOException - in case of error.
      • getShapeElementType

        public ShapeElementType getShapeElementType()
        Replies the type of the elements stored in the file.

        This type of element is extracted from header.

        Returns:
        the type of element, or null if the header could not be read.
      • getFileReadingPosition

        public int getFileReadingPosition()
                                   throws IOException
        Replies the count of bytes read from the shape file.
        Returns:
        the count of bytes read from shape file.
        Throws:
        IOException - in case of error.
      • getBoundsFromHeader

        public ESRIBounds getBoundsFromHeader()
        Replies the bounds read from the shape file header.
        Returns:
        the bounds or null
      • readHeader

        public final void readHeader()
                              throws IOException
        Read the header of the shape file.
        Throws:
        IOException - in case of error.
      • disableSeek

        public void disableSeek()
                         throws IOException
        Disable the seek feature to have lower memory foot-print. This function should be print before any invocation (directly or indirectly) to readHeader().
        Throws:
        IOException - in case of error.
      • isSeekEnabled

        @Pure
        public boolean isSeekEnabled()
        Replies if the seek feature is enabled.
        Returns:
        true if the seek feature is enabled, otherwise false
      • seek

        public abstract void seek​(int recordIndex)
                           throws IOException
        Move the reading head at the specified record index.

        If the index is negative, the next record to read is assumed to be the first record. If the index is greater or equals to the count of records, the exception EOFException will be thrown.

        Parameters:
        recordIndex - is the index of record to reply at the next read.
        Throws:
        IOException - in case of error.
      • read

        public E read()
               throws IOException
        Read the elements for a shape file.
        Returns:
        the list of the elements read from the Shape file or null on end-of-file.
        Throws:
        IOException - in case of error.
      • readRecord

        protected abstract E readRecord​(int recordIndex)
                                 throws EOFException,
                                        IOException
        Read a record according to its type.
        Parameters:
        recordIndex - is the index of the read record.
        Returns:
        the element extracted from the record
        Throws:
        EOFException - if EOF is reach to early.
        IOException - in case of error.
      • preReadingStage

        protected void preReadingStage()
                                throws IOException
        Called after the reader was initialized and before the header of the shape file was read.
        Throws:
        IOException - in case of error.
      • postReadingStage

        protected void postReadingStage​(boolean success)
                                 throws IOException
        Called after all the entries was read.
        Parameters:
        success - is true is the reading was successfull, otherwhise false.
        Throws:
        IOException - in case of error.
      • postRecordReadingStage

        protected boolean postRecordReadingStage​(E element_representation)
                                          throws IOException
        Called just after an entry was read but just before the dBase attributes were read.
        Parameters:
        element_representation - is the value returned by the reading function.
        Returns:
        true if the object is assumed to be valid (ie. replies by the reading function, otherwhise false.
        Throws:
        IOException - in case of error.
      • postHeaderReadingStage

        protected void postHeaderReadingStage()
                                       throws IOException
        Called just after the header was read.
        Throws:
        IOException - in case of error.
      • iterator

        public Iterator<E> iterator​(boolean disableSeek)
        Returns an iterator over a set of elements of type E. The seek feature is not automatically disabled when invoking this function. See iterator() to disable seek automatically.
        Parameters:
        disableSeek - indicates if the seek feature must be disabled or not.
        Returns:
        an Iterator.
        See Also:
        iterator(), iterator(Class), iterator(Class,boolean), disableSeek()
      • iterator

        public <EE extends EIterator<EE> iterator​(Class<EE> type)
        Returns an iterator over a set of elements of type E. The seek feature is automatically disabled when invoking this function. See iterator(boolean) to prevent seek disabling.
        Type Parameters:
        EE - is the type of the elements to reply.
        Parameters:
        type - is the type of the elements to reply.
        Returns:
        an Iterator.
        See Also:
        iterator(), iterator(boolean), iterator(Class,boolean), disableSeek()
      • iterator

        public <EE extends EIterator<EE> iterator​(Class<EE> type,
                                                    boolean disableSeek)
        Returns an iterator over a set of elements of type E. The seek feature is not automatically disabled when invoking this function. See iterator() to disable seek automatically.
        Type Parameters:
        EE - is the type of the elements to reply.
        Parameters:
        type - is the type of the elements to reply.
        disableSeek - indicates if the seek feature must be disabled or not.
        Returns:
        an Iterator.
        See Also:
        iterator(), iterator(boolean), iterator(Class), disableSeek()
      • setReadingPosition

        protected void setReadingPosition​(int recordIndex,
                                          int byteIndex)
                                   throws IOException
        Set the reading position, excluding the header.
        Parameters:
        recordIndex - is the index of the next record to read.
        byteIndex - is the index of the next byte to read (excluding the header).
        Throws:
        IOException - in case of error.
      • ensureAvailableBytes

        protected void ensureAvailableBytes​(int amount)
                                     throws IOException
        Ensure that the reading buffer is containing enoug bytes to read.
        Parameters:
        amount - is the count of expected bytes
        Throws:
        IOException - in case of error.
      • skipBytes

        protected void skipBytes​(int amount)
                          throws IOException
        Skip an amount of bytes.
        Parameters:
        amount - the amount to skip.
        Throws:
        IOException - in case of error.
      • readBEInt

        protected final int readBEInt()
                               throws IOException
        Read a big endian 4-byte integer.
        Returns:
        a big endian 4-byte integer.
        Throws:
        IOException - in case of error.
      • readBEDouble

        protected final double readBEDouble()
                                     throws IOException
        Read a big endian 8-byte floating point number.
        Returns:
        a big endian 8-byte floating point number.
        Throws:
        IOException - in case of error.
      • readLEInt

        protected final int readLEInt()
                               throws IOException
        Read a little endian 4-byte integer.
        Returns:
        a little endian 4-byte integer.
        Throws:
        IOException - in case of error.
      • readLEDouble

        protected final double readLEDouble()
                                     throws IOException
        Read a little endian 8-byte floating point number.
        Returns:
        a little endian 8-byte floating point number.
        Throws:
        IOException - in case of error.