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
ConstructorsConstructorDescriptionRandomAccessDataFile(File file) Create a newRandomAccessDataFilebacked by the specified file. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()getFile()Returns the underlying File.Returns anInputStreamthat can be used to read the underlying data.longgetSize()Returns the size of the data.getSubsection(long offset, long length) Returns a newRandomAccessDatafor 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 thelengthbytes of data starting at the givenoffset.
-
Constructor Details
-
RandomAccessDataFile
Create a newRandomAccessDataFilebacked 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:RandomAccessDataReturns anInputStreamthat can be used to read the underlying data. The caller is responsible close the underlying stream.- Specified by:
getInputStreamin 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:RandomAccessDataReturns a newRandomAccessDatafor a specific subsection of this data.- Specified by:
getSubsectionin interfaceRandomAccessData- Parameters:
offset- the offset of the subsectionlength- the length of the subsection- Returns:
- the subsection data
-
read
Description copied from interface:RandomAccessDataReads all the data and returns it as a byte array.- Specified by:
readin interfaceRandomAccessData- Returns:
- the data
- Throws:
IOException- if the data cannot be read
-
read
Description copied from interface:RandomAccessDataReads thelengthbytes of data starting at the givenoffset.- Specified by:
readin 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:RandomAccessDataReturns the size of the data.- Specified by:
getSizein interfaceRandomAccessData- Returns:
- the size
-
close
- Throws:
IOException
-