Class RandomAccessDataFile
- java.lang.Object
- org.springframework.boot.loader.data.RandomAccessDataFile
- All Implemented Interfaces:
RandomAccessData
public class RandomAccessDataFile extends Object implements RandomAccessData
RandomAccessDataimplementation backed by aRandomAccessFile.
Constructor Summary
Constructors Constructor Description RandomAccessDataFile(File file)Create a newRandomAccessDataFilebacked by the specified file.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()FilegetFile()Returns the underlying File.InputStreamgetInputStream()Returns anInputStreamthat can be used to read the underlying data.longgetSize()Returns the size of the data.RandomAccessDatagetSubsection(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 Detail
RandomAccessDataFile
public RandomAccessDataFile(File file)
Create a newRandomAccessDataFilebacked by the specified file.- Parameters:
file- the underlying file- Throws:
IllegalArgumentException- if the file is null or does not exist
Method Detail
getInputStream
public InputStream getInputStream() throws IOException
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
public RandomAccessData getSubsection(long offset, long length)
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
public byte[] read() throws IOException
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
public byte[] read(long offset, long length) throws IOException
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
public void close() throws IOException
- Throws:
IOException