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
Modifier and TypeFieldDescriptionstatic final ByteProvider
A static re-usable emptyByteProvider
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Releases any resources theByteProvider
may have occupiedReturns the absolute path (similar to, but not a, URI) to theByteProvider
.getFile()
Returns the underlyingFile
for thisByteProvider
, or null if thisByteProvider
is not associated with aFile
.default FSRL
getFSRL()
Returns theFSRL
of the underlying file for this byte provider, or null if this byte provider is not associated with a file.default InputStream
getInputStream
(long index) Returns an input stream to the underlying byte provider starting at the specified index.getName()
Returns the name of theByteProvider
.default boolean
isEmpty()
Returns true if this ByteProvider does not contain any bytes.boolean
isValidIndex
(long index) Returns true if the specified index is valid.long
length()
Returns the length of theByteProvider
byte
readByte
(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 emptyByteProvider
instance.
-
-
Method Details
-
getFSRL
Returns theFSRL
of the underlying file for this byte provider, or null if this byte provider is not associated with a file. -
getFile
File getFile()Returns the underlyingFile
for thisByteProvider
, or null if thisByteProvider
is 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
ByteProvider
or 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
ByteProvider
or 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 theByteProvider
may have occupied- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in 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
InputStream
instance.If you need to override this default implementation, please document why your inputstream is needed.
- Parameters:
index
- where in theByteProvider
to start theInputStream
- Returns:
- the
InputStream
- Throws:
IOException
- if an I/O error occurs
-