Package ghidra.app.util.bin
Interface ByteProvider
-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable
- All Known Subinterfaces:
MutableByteProvider
- All Known Implementing Classes:
ByteArrayProvider,ByteProviderWrapper,EmptyByteProvider,FileByteProvider,FileBytesProvider,InputStreamByteProvider,MemBufferByteProvider,MemoryByteProvider,MemoryMutableByteProvider,ObfuscatedFileByteProvider,RandomAccessByteProvider,RandomAccessMutableByteProvider,RangeMappedByteProvider,RefdByteProvider,SynchronizedByteProvider
public interface ByteProvider extends java.io.CloseableAn interface for a generic random-access byte provider.
-
-
Field Summary
Fields Modifier and Type Field Description static ByteProviderEMPTY_BYTEPROVIDERA static re-usable emptyByteProviderinstance.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclose()Releases any resources theByteProvidermay have occupiedjava.lang.StringgetAbsolutePath()Returns the absolute path (similar to, but not a, URI) to theByteProvider.java.io.FilegetFile()Returns the underlyingFilefor thisByteProvider, or null if thisByteProvideris not associated with aFile.default FSRLgetFSRL()Returns theFSRLof the underlying file for this byte provider, or null if this byte provider is not associated with a file.default java.io.InputStreamgetInputStream(long index)Returns an input stream to the underlying byte provider starting at the specified index.java.lang.StringgetName()Returns the name of theByteProvider.booleanisValidIndex(long index)Returns true if the specified index is valid.longlength()Returns the length of theByteProviderbytereadByte(long index)Reads a byte at the specified indexbyte[]readBytes(long index, long length)Reads a byte array at the specified index
-
-
-
Field Detail
-
EMPTY_BYTEPROVIDER
static final ByteProvider EMPTY_BYTEPROVIDER
A static re-usable emptyByteProviderinstance.
-
-
Method Detail
-
getFSRL
default FSRL getFSRL()
Returns theFSRLof the underlying file for this byte provider, or null if this byte provider is not associated with a file.- Returns:
- The
FSRLof the underlyingFile, or null if no associatedFile.
-
getFile
java.io.File getFile()
Returns the underlyingFilefor thisByteProvider, or null if thisByteProvideris not associated with aFile.- Returns:
- the underlying file for this byte provider
-
getName
java.lang.String getName()
Returns the name of theByteProvider. For example, the underlying file name.- Returns:
- the name of the
ByteProvideror null if there is no name
-
getAbsolutePath
java.lang.String getAbsolutePath()
Returns the absolute path (similar to, but not a, URI) to theByteProvider. For example, the complete path to the file.- Returns:
- the absolute path to the
ByteProvideror null if not associated with aFile.
-
length
long length() throws java.io.IOExceptionReturns the length of theByteProvider- Returns:
- the length of the
ByteProvider - Throws:
java.io.IOException- if an I/O error occurs
-
isValidIndex
boolean isValidIndex(long index)
Returns true if the specified index is valid.- Parameters:
index- the index in the byte provider to check- Returns:
- true if the specified index is valid
-
close
void close() throws java.io.IOExceptionReleases any resources theByteProvidermay have occupied- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException- if an I/O error occurs
-
readByte
byte readByte(long index) throws java.io.IOExceptionReads a byte at the specified index- Parameters:
index- the index of the byte to read- Returns:
- the byte read from the specified index
- Throws:
java.io.IOException- if an I/O error occurs
-
readBytes
byte[] readBytes(long index, long length) throws java.io.IOExceptionReads a byte array at the specified index- Parameters:
index- the index of the byte to readlength- the number of bytes to read- Returns:
- the byte array read from the specified index
- Throws:
java.io.IOException- if an I/O error occurs
-
getInputStream
default java.io.InputStream getInputStream(long index) throws java.io.IOExceptionReturns an input stream to the underlying byte provider starting at the specified index.The caller is responsible for closing the returned
InputStreaminstance.If you need to override this default implementation, please document why your inputstream is needed.
- Parameters:
index- where in theByteProviderto start theInputStream- Returns:
- the
InputStream - Throws:
java.io.IOException- if an I/O error occurs
-
-