Package org.jmrtd.io

Class FragmentBuffer

    • Constructor Detail

      • FragmentBuffer

        public FragmentBuffer()
        Creates a fragment buffer with default size.
      • FragmentBuffer

        public FragmentBuffer​(int length)
        Creates a fragment buffer.
        Parameters:
        length - the length of the buffer
    • Method Detail

      • updateFrom

        public void updateFrom​(FragmentBuffer other)
        Updates this buffer based on the given buffer.
        Parameters:
        other - some other fragment buffer
      • addFragment

        public void addFragment​(int offset,
                                byte b)
        Adds a fragment containing the given byte.
        Parameters:
        offset - the offset
        b - the byte to insert
      • addFragment

        public void addFragment​(int offset,
                                byte[] bytes)
        Adds a fragment of bytes at a specific offset to this file.
        Parameters:
        offset - the fragment offset
        bytes - the bytes from which fragment content will be copied
      • addFragment

        public void addFragment​(int offset,
                                byte[] bytes,
                                int srcOffset,
                                int srcLength)
        Adds a fragment of bytes at a specific offset to this file.
        Parameters:
        offset - the fragment offset
        bytes - the bytes from which fragment contents will be copied
        srcOffset - the offset within bytes where the contents of the fragment start
        srcLength - the length of the fragment
      • getPosition

        public int getPosition()
        Returns the position within the buffer. This is the upper limit of the farthest fragment read so far.
        Returns:
        the position within the buffer
      • getBytesBuffered

        public int getBytesBuffered()
        Returns the number of bytes currently buffered.
        Returns:
        the number of bytes currently buffered
      • isCoveredByFragment

        public boolean isCoveredByFragment​(int offset)
        Checks whether the byte at the given offset is covered by a fragment.
        Parameters:
        offset - the offset
        Returns:
        a boolean indicating whether the byte at the given offset is covered
      • isCoveredByFragment

        public boolean isCoveredByFragment​(int offset,
                                           int length)
        Checks whether the segment specified by the given offset and length is completely covered by fragments.
        Parameters:
        offset - the given offset
        length - the given length
        Returns:
        a boolean indicating whether the specified segment is fully covered
      • getBufferedLength

        public int getBufferedLength​(int index)
        Calculates the number of bytes left in the buffer starting from index index.
        Parameters:
        index - the index
        Returns:
        the number of bytes left in the buffer
      • getBuffer

        public byte[] getBuffer()
        Returns the current buffer.
        Returns:
        the buffer
      • getLength

        public int getLength()
        Returns the buffer (the size of the underlying byte array).
        Returns:
        the size of the buffer
      • getSmallestUnbufferedFragment

        public FragmentBuffer.Fragment getSmallestUnbufferedFragment​(int offset,
                                                                     int length)
        Gets the smallest fragment that contains offset and offset + length that has not been buffered in this buffer.
        Parameters:
        offset - the offset
        length - the length
        Returns:
        the fragment that has not yet been buffered
      • equals

        public boolean equals​(Object otherObject)
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object