Class RandomAccessDataFile
java.lang.Object
org.springframework.boot.loader.data.RandomAccessDataFile
- All Implemented Interfaces:
RandomAccessData
RandomAccessData
implementation backed by a RandomAccessFile
.- Since:
- 1.0.0
- Author:
- Phillip Webb, Andy Wilkinson
-
Constructor Summary
ConstructorDescriptionRandomAccessDataFile
(File file) Create a newRandomAccessDataFile
backed by the specified file. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
getFile()
Returns the underlying File.Returns 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
.
-
Constructor Details
-
RandomAccessDataFile
Create a newRandomAccessDataFile
backed by the specified file.- Parameters:
file
- the underlying file- Throws:
IllegalArgumentException
- if the file is null or does not exist
-
-
Method Details
-
getFile
Returns the underlying File.- Returns:
- the underlying file
-
getInputStream
Description copied from interface:RandomAccessData
Returns anInputStream
that can be used to read the underlying data. The caller is responsible close the underlying stream.- Specified by:
getInputStream
in interfaceRandomAccessData
- Returns:
- a new input stream that can be used to read the underlying data.
- Throws:
IOException
- if the stream cannot be opened
-
getSubsection
Description copied from interface:RandomAccessData
Returns a newRandomAccessData
for a specific subsection of this data.- Specified by:
getSubsection
in interfaceRandomAccessData
- Parameters:
offset
- the offset of the subsectionlength
- the length of the subsection- Returns:
- the subsection data
-
read
Description copied from interface:RandomAccessData
Reads all the data and returns it as a byte array.- Specified by:
read
in interfaceRandomAccessData
- Returns:
- the data
- Throws:
IOException
- if the data cannot be read
-
read
Description copied from interface:RandomAccessData
Reads thelength
bytes of data starting at the givenoffset
.- Specified by:
read
in interfaceRandomAccessData
- 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 readEOFException
- if offset plus length is greater than the length of the file or subsection
-
getSize
public long getSize()Description copied from interface:RandomAccessData
Returns the size of the data.- Specified by:
getSize
in interfaceRandomAccessData
- Returns:
- the size
-
close
- Throws:
IOException
-