Package org.exbin.auxiliary.paged_data
Class ByteArrayEditableData
- java.lang.Object
-
- org.exbin.auxiliary.paged_data.ByteArrayData
-
- org.exbin.auxiliary.paged_data.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.
-
-
Field Summary
Fields Modifier and Type Field Description static int
BUFFER_SIZE
static int
MAX_ARRAY_LENGTH
-
Fields inherited from class org.exbin.auxiliary.paged_data.ByteArrayData
data
-
-
Constructor Summary
Constructors Constructor Description ByteArrayEditableData()
ByteArrayEditableData(byte[] 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 org.exbin.auxiliary.paged_data.ByteArrayData
compareTo, copyToArray, dispose, equals, getByte, getData, getDataInputStream, getDataLength, getDataSize, hashCode, isEmpty, saveToStream, setData
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.exbin.auxiliary.paged_data.BinaryData
copyToArray, dispose, getByte, getDataInputStream, getDataSize, isEmpty, saveToStream
-
-
-
-
Field Detail
-
BUFFER_SIZE
public static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
MAX_ARRAY_LENGTH
public static final int MAX_ARRAY_LENGTH
- See Also:
- Constant Field Values
-
-
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 interfaceEditableBinaryData
- 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 interfaceEditableBinaryData
- Parameters:
position
- positionvalue
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- position to insert tolength
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- position to insert tolength
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- position to insert toinsertedData
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- position to insert toinsertedData
- data to insertinsertedDataOffset
- inserted data offsetlength
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- position to insert toinsertedData
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- position to insert toinsertedData
- data to insertinsertedDataOffset
- inserted data offsetinsertedDataLength
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- start position to insert datainputStream
- input streamdataSize
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- position to fill data tolength
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- position to fill data tolength
- length of areafill
- 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 interfaceEditableBinaryData
- Parameters:
targetPosition
- target position to write tosourceData
- 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 interfaceEditableBinaryData
- Parameters:
targetPosition
- target position to write toreplacingData
- data to read fromstartFrom
- position to start copy fromreplacingLength
- 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 interfaceEditableBinaryData
- Parameters:
targetPosition
- target position to write toreplacingData
- 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 interfaceEditableBinaryData
- Parameters:
targetPosition
- target position to write toreplacingData
- data to read fromreplacingDataOffset
- position to start copy fromlength
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- position to start removal fromlength
- length of area
-
copy
@Nonnull public BinaryData copy()
Description copied from interface:BinaryData
Creates copy of all data.- Specified by:
copy
in interfaceBinaryData
- Overrides:
copy
in classByteArrayData
- Returns:
- copy of data
-
copy
@Nonnull public BinaryData copy(long startFrom, long length)
Description copied from interface:BinaryData
Creates copy of given area.- Specified by:
copy
in interfaceBinaryData
- Overrides:
copy
in classByteArrayData
- Parameters:
startFrom
- position to start copy fromlength
- 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 interfaceEditableBinaryData
-
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 interfaceEditableBinaryData
- 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 interfaceEditableBinaryData
- Returns:
- new instance of output stream
-
-