public class RandomAccessDataFile extends Object implements RandomAccessData
RandomAccessData
implementation backed by a RandomAccessFile
.Constructor and Description |
---|
RandomAccessDataFile(File file)
Create a new
RandomAccessDataFile backed by the specified file. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
File |
getFile()
Returns the underlying File.
|
InputStream |
getInputStream()
Returns an
InputStream that can be used to read the underlying data. |
long |
getSize()
Returns the size of the data.
|
RandomAccessData |
getSubsection(long offset,
long length)
Returns a new
RandomAccessData 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 the
length bytes of data starting at the given offset . |
public RandomAccessDataFile(File file)
RandomAccessDataFile
backed by the specified file.file
- the underlying fileIllegalArgumentException
- if the file is null or does not existpublic File getFile()
public InputStream getInputStream() throws IOException
RandomAccessData
InputStream
that can be used to read the underlying data. The
caller is responsible close the underlying stream.getInputStream
in interface RandomAccessData
IOException
- if the stream cannot be openedpublic RandomAccessData getSubsection(long offset, long length)
RandomAccessData
RandomAccessData
for a specific subsection of this data.getSubsection
in interface RandomAccessData
offset
- the offset of the subsectionlength
- the length of the subsectionpublic byte[] read() throws IOException
RandomAccessData
read
in interface RandomAccessData
IOException
- if the data cannot be readpublic byte[] read(long offset, long length) throws IOException
RandomAccessData
length
bytes of data starting at the given offset
.read
in interface RandomAccessData
offset
- the offset from which data should be readlength
- the number of bytes to be readIOException
- if the data cannot be readEOFException
- if offset plus length is greater than the length of the file
or subsectionpublic long getSize()
RandomAccessData
getSize
in interface RandomAccessData
public void close() throws IOException
IOException
Copyright © 2019 Pivotal Software, Inc.. All rights reserved.