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 theRandomAccessData
interface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RandomAccessDataFactory.AccessType
This enum describes different methods to access files through aRandomAccessData
interface.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static RandomAccessData
createInstance(byte[] bytes)
Creates a byte array based instance of aRandomAccessData
type.static RandomAccessData
createInstance(RandomAccessData data, long offset, long length)
Creates aRandomAccessData
source for accessing a limited area of an underlyingRandomAccessData
source.static RandomAccessData
createInstance(File file, RandomAccessDataFactory.AccessType accessType)
Creates aFile
based instance of aRandomAccessData
type.static RandomAccessData
createInstance(Path file)
-
-
-
Method Detail
-
createInstance
public static RandomAccessData createInstance(File file, RandomAccessDataFactory.AccessType accessType) throws RandomAccessDataException
Creates aFile
based instance of aRandomAccessData
type.- Parameters:
file
- the file to accessaccessType
- the fileaccess type
(a null value defaults toRandomAccessDataFactory.AccessType.RANDOM
)- Returns:
- a new
RandomAccessData
instance - 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 aRandomAccessData
type.- Parameters:
bytes
- the byte array containing the data to read- Returns:
- a new
RandomAccessData
instance - Throws:
RandomAccessDataException
- if argument is null
-
createInstance
public static RandomAccessData createInstance(RandomAccessData data, long offset, long length) throws RandomAccessDataException
Creates aRandomAccessData
source for accessing a limited area of an underlyingRandomAccessData
source. 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
RandomAccessData
instance - 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
RandomAccessData
instance - Throws:
RandomAccessDataException
- if file could not be read
-
-