Class ByteArrayEditableData

  • All Implemented Interfaces:
    BinaryData, DataPage, EditableBinaryData

    @ParametersAreNonnullByDefault
    public class ByteArrayEditableData
    extends ByteArrayData
    implements EditableBinaryData
    Basic implementation of editable binary data interface using byte array. This implementation is highly inefficient with resources and is not recommended for frequently changed data as each change creates copy of data.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Removes all existing data.
      BinaryData copy()
      Creates copy of all data.
      BinaryData copy​(long startFrom, long length)
      Creates copy of given area.
      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.
      java.io.OutputStream getDataOutputStream()
      Provides handler for output stream generation.
      void insert​(long startFrom, byte[] insertedData)
      Inserts given data to given position.
      void insert​(long startFrom, byte[] insertedData, int insertedDataOffset, int length)
      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.
      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 sourceData)
      Replaces data in given area with provided data.
      void replace​(long targetPosition, BinaryData replacingData, long startFrom, long replacingLength)
      Replaces data in given area with provided data.
      void setByte​(long position, byte value)
      Sets byte to given position.
      void setDataSize​(long size)
      Sets data size.
      • Methods inherited from class java.lang.Object

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

      • ByteArrayEditableData

        public ByteArrayEditableData()
      • ByteArrayEditableData

        public ByteArrayEditableData​(@Nullable
                                     byte[] data)
    • Method Detail

      • 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
      • 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,
                           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 length)
        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
        length - inserted data length
      • 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 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
      • replace

        public void replace​(long targetPosition,
                            BinaryData sourceData)
        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
        sourceData - data to read from
      • replace

        public void replace​(long targetPosition,
                            BinaryData replacingData,
                            long startFrom,
                            long replacingLength)
        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
        replacingLength - 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
      • 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
      • copy

        @Nonnull
        public BinaryData copy​(long startFrom,
                               long length)
        Description copied from interface: BinaryData
        Creates copy of given area.
        Specified by:
        copy in interface BinaryData
        Overrides:
        copy in class ByteArrayData
        Parameters:
        startFrom - position to start copy from
        length - length of area
        Returns:
        copy of data
      • 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
      • 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
      • 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