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 intBUFFER_SIZEstatic intMAX_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 voidclear()Removes all existing data.BinaryDatacopy()Creates copy of all data.BinaryDatacopy(long startFrom, long length)Creates copy of given area.voidfillData(long startFrom, long length)Fills given area with empty data.voidfillData(long startFrom, long length, byte fill)Fills given area with bytes of given value.java.io.OutputStreamgetDataOutputStream()Provides handler for output stream generation.voidinsert(long startFrom, byte[] insertedData)Inserts given data to given position.voidinsert(long startFrom, byte[] insertedData, int insertedDataOffset, int length)Inserts given data to given position.voidinsert(long startFrom, long length)Inserts empty data of given length to given position.longinsert(long startFrom, java.io.InputStream inputStream, long dataSize)Loads data from given stream expecting provided size.voidinsert(long startFrom, BinaryData insertedData)Inserts given data to given position.voidinsert(long startFrom, BinaryData insertedData, long insertedDataOffset, long insertedDataLength)Inserts given data to given position.voidinsertUninitialized(long startFrom, long length)Inserts data space of given length to given position without setting any data to it.voidloadFromStream(java.io.InputStream inputStream)Replaces all data by data red from given stream.voidremove(long startFrom, long length)Removes area of data.voidreplace(long targetPosition, byte[] replacingData)Replaces data in given area with provided data.voidreplace(long targetPosition, byte[] replacingData, int replacingDataOffset, int length)Replaces data in given area with provided data.voidreplace(long targetPosition, BinaryData sourceData)Replaces data in given area with provided data.voidreplace(long targetPosition, BinaryData replacingData, long startFrom, long replacingLength)Replaces data in given area with provided data.voidsetByte(long position, byte value)Sets byte to given position.voidsetDataSize(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:EditableBinaryDataSets data size. If size is bigger than current size, it will fill it with zeros, otherwise it will shrink current data.- Specified by:
setDataSizein interfaceEditableBinaryData- Parameters:
size- target size
-
setByte
public void setByte(long position, byte value)Description copied from interface:EditableBinaryDataSets byte to given position.- Specified by:
setBytein interfaceEditableBinaryData- Parameters:
position- positionvalue- byte value to be set
-
insertUninitialized
public void insertUninitialized(long startFrom, long length)Description copied from interface:EditableBinaryDataInserts data space of given length to given position without setting any data to it.- Specified by:
insertUninitializedin interfaceEditableBinaryData- Parameters:
startFrom- position to insert tolength- length of data
-
insert
public void insert(long startFrom, long length)Description copied from interface:EditableBinaryDataInserts empty data of given length to given position.- Specified by:
insertin interfaceEditableBinaryData- Parameters:
startFrom- position to insert tolength- length of data
-
insert
public void insert(long startFrom, byte[] insertedData)Description copied from interface:EditableBinaryDataInserts given data to given position.- Specified by:
insertin 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:EditableBinaryDataInserts given data to given position.- Specified by:
insertin 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:EditableBinaryDataInserts given data to given position.- Specified by:
insertin 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:EditableBinaryDataInserts given data to given position.- Specified by:
insertin 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.IOExceptionDescription copied from interface:EditableBinaryDataLoads data from given stream expecting provided size. Preserves original data outside loaded range. Extends data if needed.- Specified by:
insertin 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:EditableBinaryDataFills given area with empty data.- Specified by:
fillDatain 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:EditableBinaryDataFills given area with bytes of given value.- Specified by:
fillDatain 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:EditableBinaryDataReplaces 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:
replacein 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:EditableBinaryDataReplaces 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:
replacein 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:EditableBinaryDataReplaces 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:
replacein 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:EditableBinaryDataReplaces 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:
replacein 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:EditableBinaryDataRemoves area of data.- Specified by:
removein interfaceEditableBinaryData- Parameters:
startFrom- position to start removal fromlength- length of area
-
copy
@Nonnull public BinaryData copy()
Description copied from interface:BinaryDataCreates copy of all data.- Specified by:
copyin interfaceBinaryData- Overrides:
copyin classByteArrayData- Returns:
- copy of data
-
copy
@Nonnull public BinaryData copy(long startFrom, long length)
Description copied from interface:BinaryDataCreates copy of given area.- Specified by:
copyin interfaceBinaryData- Overrides:
copyin classByteArrayData- Parameters:
startFrom- position to start copy fromlength- length of area- Returns:
- copy of data
-
clear
public void clear()
Description copied from interface:EditableBinaryDataRemoves all existing data. Simply releases all references to data pages.- Specified by:
clearin interfaceEditableBinaryData
-
loadFromStream
public void loadFromStream(java.io.InputStream inputStream) throws java.io.IOExceptionDescription copied from interface:EditableBinaryDataReplaces all data by data red from given stream.- Specified by:
loadFromStreamin interfaceEditableBinaryData- Parameters:
inputStream- input stream- Throws:
java.io.IOException- if input/output error
-
getDataOutputStream
@Nonnull public java.io.OutputStream getDataOutputStream()
Description copied from interface:EditableBinaryDataProvides handler for output stream generation. Received data are appended to existing data.- Specified by:
getDataOutputStreamin interfaceEditableBinaryData- Returns:
- new instance of output stream
-
-