Interface RandomAccessData
- All Known Implementing Classes:
RandomAccessDataFile
public interface RandomAccessData
Interface that provides read-only random access to some underlying data.
Implementations must allow concurrent reads in a thread-safe manner.
- Since:
- 1.0.0
- Author:
- Phillip Webb
-
Method Summary
Modifier and TypeMethodDescriptionReturns anInputStream
that can be used to read the underlying data.long
getSize()
Returns the size of the data.getSubsection
(long offset, long length) Returns a newRandomAccessData
for a specific subsection of this data.byte[]
read()
Reads all the data and returns it as a byte array.byte[]
read
(long offset, long length) Reads thelength
bytes of data starting at the givenoffset
.
-
Method Details
-
getInputStream
Returns anInputStream
that can be used to read the underlying data. The caller is responsible close the underlying stream.- Returns:
- a new input stream that can be used to read the underlying data.
- Throws:
IOException
- if the stream cannot be opened
-
getSubsection
Returns a newRandomAccessData
for a specific subsection of this data.- Parameters:
offset
- the offset of the subsectionlength
- the length of the subsection- Returns:
- the subsection data
-
read
Reads all the data and returns it as a byte array.- Returns:
- the data
- Throws:
IOException
- if the data cannot be read
-
read
Reads thelength
bytes of data starting at the givenoffset
.- Parameters:
offset
- the offset from which data should be readlength
- the number of bytes to be read- Returns:
- the data
- Throws:
IOException
- if the data cannot be readIndexOutOfBoundsException
- if offset is beyond the end of the file or subsectionEOFException
- if offset plus length is greater than the length of the file or subsection
-
getSize
long getSize()Returns the size of the data.- Returns:
- the size
-