Class RandomAccessDataFactory
- java.lang.Object
-
- de.bernd_michaely.common.io.random.RandomAccessDataFactory
-
public class RandomAccessDataFactory extends Object
Factory class to create instances of objects implementing theRandomAccessDatainterface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRandomAccessDataFactory.AccessTypeThis enum describes different methods to access files through aRandomAccessDatainterface.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RandomAccessDatacreateInstance(byte[] bytes)Creates a byte array based instance of aRandomAccessDatatype.static RandomAccessDatacreateInstance(RandomAccessData data, long offset, long length)Creates aRandomAccessDatasource for accessing a limited area of an underlyingRandomAccessDatasource.static RandomAccessDatacreateInstance(File file, RandomAccessDataFactory.AccessType accessType)Creates aFilebased instance of aRandomAccessDatatype.static RandomAccessDatacreateInstance(Path file)
-
-
-
Method Detail
-
createInstance
public static RandomAccessData createInstance(File file, RandomAccessDataFactory.AccessType accessType) throws RandomAccessDataException
Creates aFilebased instance of aRandomAccessDatatype.- Parameters:
file- the file to accessaccessType- the fileaccess type(a null value defaults toRandomAccessDataFactory.AccessType.RANDOM)- Returns:
- a new
RandomAccessDatainstance - Throws:
RandomAccessDataException- if file could not be read- Since:
- 2.0
-
createInstance
public static RandomAccessData createInstance(byte[] bytes) throws RandomAccessDataException
Creates a byte array based instance of aRandomAccessDatatype.- Parameters:
bytes- the byte array containing the data to read- Returns:
- a new
RandomAccessDatainstance - Throws:
RandomAccessDataException- if argument is null
-
createInstance
public static RandomAccessData createInstance(RandomAccessData data, long offset, long length) throws RandomAccessDataException
Creates aRandomAccessDatasource for accessing a limited area of an underlyingRandomAccessDatasource. The current offset is initially adapted according to the source data's current offset.- Parameters:
data- the source data (null will be treated like closed)offset- the offset to the data sourcelength- the length within the data source- Returns:
- a new
RandomAccessDatainstance - Throws:
RandomAccessDataException- passed through errors by accessing dataIllegalArgumentException- if offset or length is negative- Since:
- 2.0
-
createInstance
public static RandomAccessData createInstance(Path file) throws RandomAccessDataException
- Parameters:
file- the file to access- Returns:
- a new
RandomAccessDatainstance - Throws:
RandomAccessDataException- if file could not be read
-
-