Package org.exbin.auxiliary.paged_data
Class PagedData
- java.lang.Object
-
- org.exbin.auxiliary.paged_data.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.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PAGE_SIZE
static long
MAX_DATA_SIZE
-
Constructor Summary
Constructors Constructor Description PagedData()
PagedData(int pageSize)
PagedData(DataPageProvider dataPageProvider)
-
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.
-
-
-
Field Detail
-
DEFAULT_PAGE_SIZE
public static final int DEFAULT_PAGE_SIZE
- See Also:
- Constant Field Values
-
MAX_DATA_SIZE
public static final long MAX_DATA_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PagedData
public PagedData()
-
PagedData
public PagedData(DataPageProvider dataPageProvider)
-
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 interfaceBinaryData
- 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 interfaceBinaryData
- 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 interfaceEditableBinaryData
- Parameters:
size
- target size
-
getByte
public byte getByte(long position)
Description copied from interface:BinaryData
Returns particular byte from data.- Specified by:
getByte
in interfaceBinaryData
- 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 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, 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 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 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
-
copy
@Nonnull public PagedData copy()
Description copied from interface:BinaryData
Creates copy of all data.- Specified by:
copy
in interfaceBinaryData
- 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 interfaceBinaryData
- Parameters:
startFrom
- position to start copy fromlength
- 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 interfaceBinaryData
- Parameters:
startFrom
- position to start copy fromtarget
- target byte arrayoffset
- offset position in targetlength
- 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 interfaceEditableBinaryData
- Parameters:
startFrom
- position to start removal fromlength
- 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 interfaceEditableBinaryData
-
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 indexdataPage
- 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 interfaceEditableBinaryData
- Parameters:
targetPosition
- target position to write toreplacingData
- 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 interfaceEditableBinaryData
- Parameters:
targetPosition
- target position to write toreplacingData
- data to read fromstartFrom
- position to start copy fromlength
- 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
-
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
-
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 interfaceBinaryData
- 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 interfaceEditableBinaryData
- 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 interfaceBinaryData
- Returns:
- new instance of input stream
-
getDataPageProvider
@Nullable public DataPageProvider getDataPageProvider()
-
setDataPageProvider
public void setDataPageProvider(@Nullable DataPageProvider dataPageProvider)
-
equals
public boolean equals(@Nullable java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
dispose
public void dispose()
Description copied from interface:BinaryData
Disposes all allocated data if possible.- Specified by:
dispose
in interfaceBinaryData
-
-