Package ghidra.app.util.bin
Interface ByteProvider
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Subinterfaces:
MutableByteProvider
- All Known Implementing Classes:
ByteArrayProvider,ByteProviderWrapper,EmptyByteProvider,FileByteProvider,FileBytesProvider,InputStreamByteProvider,MemBufferByteProvider,MemoryByteProvider,MemoryMutableByteProvider,ObfuscatedFileByteProvider,RandomAccessByteProvider,RandomAccessMutableByteProvider,RangeMappedByteProvider,RefdByteProvider,SynchronizedByteProvider,UnlimitedByteProviderWrapper
An interface for a generic random-access byte provider.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ByteProviderA static re-usable emptyByteProviderinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases any resources theByteProvidermay have occupiedReturns the absolute path (similar to, but not a, URI) to theByteProvider.getFile()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 InputStreamgetInputStream(long index) Returns an input stream to the underlying byte provider starting at the specified index.getName()Returns the name of theByteProvider.default booleanisEmpty()Returns true if this ByteProvider does not contain any bytes.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 Details
-
EMPTY_BYTEPROVIDER
A static re-usable emptyByteProviderinstance.
-
-
Method Details
-
getFSRL
Returns theFSRLof the underlying file for this byte provider, or null if this byte provider is not associated with a file. -
getFile
File getFile()Returns the underlyingFilefor thisByteProvider, or null if thisByteProvideris not associated with aFile.- Returns:
- the underlying file for this byte provider
-
getName
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
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
Returns the length of theByteProvider- Returns:
- the length of the
ByteProvider - Throws:
IOException- if an I/O error occurs
-
isEmpty
default boolean isEmpty()Returns true if this ByteProvider does not contain any bytes.- Returns:
- boolean true if this provider is empty, false if contains bytes
-
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
Releases any resources theByteProvidermay have occupied- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if an I/O error occurs
-
readByte
Reads a byte at the specified index- Parameters:
index- the index of the byte to read- Returns:
- the byte read from the specified index
- Throws:
IOException- if an I/O error occurs
-
readBytes
Reads 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:
IOException- if an I/O error occurs
-
getInputStream
Returns 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:
IOException- if an I/O error occurs
-