Class PagedData

  • All Implemented Interfaces:
    BinaryData, EditableBinaryData

    @ParametersAreNonnullByDefault
    public class PagedData
    extends java.lang.Object
    implements EditableBinaryData
    Encapsulation class for binary data blob. Data are stored using paging. Last page might be shorter than page size, but not empty.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all existing data.
      PagedData copy()
      Creates copy of all data.
      PagedData copy​(long startFrom, long length)
      Creates copy of given area.
      void copyToArray​(long startFrom, byte[] target, int offset, int length)
      Creates copy of given area into array of bytes.
      void dispose()
      Disposes all allocated data if possible.
      boolean equals​(java.lang.Object obj)  
      void fillData​(long startFrom, long length)
      Fills given area with empty data.
      void fillData​(long startFrom, long length, byte fill)
      Fills given area with bytes of given value.
      byte getByte​(long position)
      Returns particular byte from data.
      java.io.InputStream getDataInputStream()
      Provides handler for input stream generation.
      java.io.OutputStream getDataOutputStream()
      Provides handler for output stream generation.
      DataPageProvider getDataPageProvider()  
      long getDataSize()
      Returns size of data or -1 if size is not available.
      byte[] getPage​(int pageIndex)
      Gets data page allowing direct access to it.
      int getPagesCount()
      returns number of pages currently used.
      int getPageSize()
      Returns currently used page size.
      int hashCode()  
      void insert​(long startFrom, byte[] insertedData)
      Inserts given data to given position.
      void insert​(long startFrom, byte[] insertedData, int insertedDataOffset, int insertedDataLength)
      Inserts given data to given position.
      void insert​(long startFrom, long length)
      Inserts empty data of given length to given position.
      long insert​(long startFrom, java.io.InputStream inputStream, long dataSize)
      Loads data from given stream expecting provided size.
      void insert​(long startFrom, BinaryData insertedData)
      Inserts given data to given position.
      void insert​(long startFrom, BinaryData insertedData, long insertedDataOffset, long insertedDataLength)
      Inserts given data to given position.
      void insertUninitialized​(long startFrom, long length)
      Inserts data space of given length to given position without setting any data to it.
      boolean isEmpty()
      Returns true if data are empty.
      void loadFromStream​(java.io.InputStream inputStream)
      Replaces all data by data red from given stream.
      void remove​(long startFrom, long length)
      Removes area of data.
      void replace​(long targetPosition, byte[] replacingData)
      Replaces data in given area with provided data.
      void replace​(long targetPosition, byte[] replacingData, int replacingDataOffset, int length)
      Replaces data in given area with provided data.
      void replace​(long targetPosition, BinaryData replacingData)
      Replaces data in given area with provided data.
      void replace​(long targetPosition, BinaryData replacingData, long startFrom, long length)
      Replaces data in given area with provided data.
      void saveToStream​(java.io.OutputStream outputStream)
      Saves/copies all data to given stream.
      void setByte​(long position, byte value)
      Sets byte to given position.
      void setDataPageProvider​(DataPageProvider dataPageProvider)  
      void setDataSize​(long size)
      Sets data size.
      void setPage​(int pageIndex, DataPage dataPage)
      Sets data page replacing existing page by reference.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PagedData

        public PagedData()
      • PagedData

        public PagedData​(int pageSize)
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Description copied from interface: BinaryData
        Returns true if data are empty.
        Specified by:
        isEmpty in interface BinaryData
        Returns:
        true if data empty
      • getDataSize

        public long getDataSize()
        Description copied from interface: BinaryData
        Returns size of data or -1 if size is not available.
        Specified by:
        getDataSize in interface BinaryData
        Returns:
        size of data in bytes
      • setDataSize

        public void setDataSize​(long size)
        Description copied from interface: EditableBinaryData
        Sets data size. If size is bigger than current size, it will fill it with zeros, otherwise it will shrink current data.
        Specified by:
        setDataSize in interface EditableBinaryData
        Parameters:
        size - target size
      • getByte

        public byte getByte​(long position)
        Description copied from interface: BinaryData
        Returns particular byte from data.
        Specified by:
        getByte in interface BinaryData
        Parameters:
        position - position
        Returns:
        byte on requested position
      • setByte

        public void setByte​(long position,
                            byte value)
        Description copied from interface: EditableBinaryData
        Sets byte to given position.
        Specified by:
        setByte in interface EditableBinaryData
        Parameters:
        position - position
        value - byte value to be set
      • insertUninitialized

        public void insertUninitialized​(long startFrom,
                                        long length)
        Description copied from interface: EditableBinaryData
        Inserts data space of given length to given position without setting any data to it.
        Specified by:
        insertUninitialized in interface EditableBinaryData
        Parameters:
        startFrom - position to insert to
        length - length of data
      • insert

        public void insert​(long startFrom,
                           long length)
        Description copied from interface: EditableBinaryData
        Inserts empty data of given length to given position.
        Specified by:
        insert in interface EditableBinaryData
        Parameters:
        startFrom - position to insert to
        length - length of data
      • insert

        public void insert​(long startFrom,
                           BinaryData insertedData)
        Description copied from interface: EditableBinaryData
        Inserts given data to given position.
        Specified by:
        insert in interface EditableBinaryData
        Parameters:
        startFrom - position to insert to
        insertedData - data to insert
      • insert

        public void insert​(long startFrom,
                           BinaryData insertedData,
                           long insertedDataOffset,
                           long insertedDataLength)
        Description copied from interface: EditableBinaryData
        Inserts given data to given position.
        Specified by:
        insert in interface EditableBinaryData
        Parameters:
        startFrom - position to insert to
        insertedData - data to insert
        insertedDataOffset - inserted data offset
        insertedDataLength - inserted data length
      • insert

        public void insert​(long startFrom,
                           byte[] insertedData)
        Description copied from interface: EditableBinaryData
        Inserts given data to given position.
        Specified by:
        insert in interface EditableBinaryData
        Parameters:
        startFrom - position to insert to
        insertedData - data to insert
      • insert

        public void insert​(long startFrom,
                           byte[] insertedData,
                           int insertedDataOffset,
                           int insertedDataLength)
        Description copied from interface: EditableBinaryData
        Inserts given data to given position.
        Specified by:
        insert in interface EditableBinaryData
        Parameters:
        startFrom - position to insert to
        insertedData - data to insert
        insertedDataOffset - inserted data offset
        insertedDataLength - inserted data length
      • insert

        public long insert​(long startFrom,
                           java.io.InputStream inputStream,
                           long dataSize)
                    throws java.io.IOException
        Description copied from interface: EditableBinaryData
        Loads data from given stream expecting provided size. Preserves original data outside loaded range. Extends data if needed.
        Specified by:
        insert in interface EditableBinaryData
        Parameters:
        startFrom - start position to insert data
        inputStream - input stream
        dataSize - size of data to load or -1 for all data
        Returns:
        length of loaded data
        Throws:
        java.io.IOException - if input/output error
      • fillData

        public void fillData​(long startFrom,
                             long length)
        Description copied from interface: EditableBinaryData
        Fills given area with empty data.
        Specified by:
        fillData in interface EditableBinaryData
        Parameters:
        startFrom - position to fill data to
        length - length of area
      • fillData

        public void fillData​(long startFrom,
                             long length,
                             byte fill)
        Description copied from interface: EditableBinaryData
        Fills given area with bytes of given value.
        Specified by:
        fillData in interface EditableBinaryData
        Parameters:
        startFrom - position to fill data to
        length - length of area
        fill - value to fill with
      • copy

        @Nonnull
        public PagedData copy()
        Description copied from interface: BinaryData
        Creates copy of all data.
        Specified by:
        copy in interface BinaryData
        Returns:
        copy of data
      • copy

        @Nonnull
        public PagedData copy​(long startFrom,
                              long length)
        Description copied from interface: BinaryData
        Creates copy of given area.
        Specified by:
        copy in interface BinaryData
        Parameters:
        startFrom - position to start copy from
        length - length of area
        Returns:
        copy of data
      • copyToArray

        public void copyToArray​(long startFrom,
                                byte[] target,
                                int offset,
                                int length)
        Description copied from interface: BinaryData
        Creates copy of given area into array of bytes.
        Specified by:
        copyToArray in interface BinaryData
        Parameters:
        startFrom - position to start copy from
        target - target byte array
        offset - offset position in target
        length - length of area to copy
      • remove

        public void remove​(long startFrom,
                           long length)
        Description copied from interface: EditableBinaryData
        Removes area of data.
        Specified by:
        remove in interface EditableBinaryData
        Parameters:
        startFrom - position to start removal from
        length - length of area
      • clear

        public void clear()
        Description copied from interface: EditableBinaryData
        Removes all existing data. Simply releases all references to data pages.
        Specified by:
        clear in interface EditableBinaryData
      • getPagesCount

        public int getPagesCount()
        returns number of pages currently used.
        Returns:
        count of pages
      • getPageSize

        public int getPageSize()
        Returns currently used page size.
        Returns:
        page size in bytes
      • getPage

        @Nonnull
        public byte[] getPage​(int pageIndex)
        Gets data page allowing direct access to it.
        Parameters:
        pageIndex - page index
        Returns:
        data page
      • setPage

        public void setPage​(int pageIndex,
                            DataPage dataPage)
        Sets data page replacing existing page by reference.
        Parameters:
        pageIndex - page index
        dataPage - data page
      • replace

        public void replace​(long targetPosition,
                            BinaryData replacingData)
        Description copied from interface: EditableBinaryData
        Replaces data in given area with provided data. If sourceData are the same instance, data are replaced as it would be copied to buffer first and replaced then.
        Specified by:
        replace in interface EditableBinaryData
        Parameters:
        targetPosition - target position to write to
        replacingData - data to read from
      • replace

        public void replace​(long targetPosition,
                            BinaryData replacingData,
                            long startFrom,
                            long length)
        Description copied from interface: EditableBinaryData
        Replaces data in given area with provided data. If sourceData are the same instance, data are replaced as it would be copied to buffer first and replaced then.
        Specified by:
        replace in interface EditableBinaryData
        Parameters:
        targetPosition - target position to write to
        replacingData - data to read from
        startFrom - position to start copy from
        length - length of data to copy
      • replace

        public void replace​(long targetPosition,
                            byte[] replacingData)
        Description copied from interface: EditableBinaryData
        Replaces data in given area with provided data. If sourceData are the same instance, data are replaced as it would be copied to buffer first and replaced then.
        Specified by:
        replace in interface EditableBinaryData
        Parameters:
        targetPosition - target position to write to
        replacingData - data to read from
      • replace

        public void replace​(long targetPosition,
                            byte[] replacingData,
                            int replacingDataOffset,
                            int length)
        Description copied from interface: EditableBinaryData
        Replaces data in given area with provided data. If sourceData are the same instance, data are replaced as it would be copied to buffer first and replaced then.
        Specified by:
        replace in interface EditableBinaryData
        Parameters:
        targetPosition - target position to write to
        replacingData - data to read from
        replacingDataOffset - position to start copy from
        length - length of data to copy
      • loadFromStream

        public void loadFromStream​(java.io.InputStream inputStream)
                            throws java.io.IOException
        Description copied from interface: EditableBinaryData
        Replaces all data by data red from given stream.
        Specified by:
        loadFromStream in interface EditableBinaryData
        Parameters:
        inputStream - input stream
        Throws:
        java.io.IOException - if input/output error
      • saveToStream

        public void saveToStream​(java.io.OutputStream outputStream)
                          throws java.io.IOException
        Description copied from interface: BinaryData
        Saves/copies all data to given stream.
        Specified by:
        saveToStream in interface BinaryData
        Parameters:
        outputStream - output stream
        Throws:
        java.io.IOException - if input/output error
      • getDataOutputStream

        @Nonnull
        public java.io.OutputStream getDataOutputStream()
        Description copied from interface: EditableBinaryData
        Provides handler for output stream generation. Received data are appended to existing data.
        Specified by:
        getDataOutputStream in interface EditableBinaryData
        Returns:
        new instance of output stream
      • getDataInputStream

        @Nonnull
        public java.io.InputStream getDataInputStream()
        Description copied from interface: BinaryData
        Provides handler for input stream generation.
        Specified by:
        getDataInputStream in interface BinaryData
        Returns:
        new instance of input stream
      • setDataPageProvider

        public void setDataPageProvider​(@Nullable
                                        DataPageProvider dataPageProvider)
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • dispose

        public void dispose()
        Description copied from interface: BinaryData
        Disposes all allocated data if possible.
        Specified by:
        dispose in interface BinaryData