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.Closeable
An interface for a generic random-access byte provider.
-
-
Field Summary
Fields Modifier and Type Field Description static ByteProvider
EMPTY_BYTEPROVIDER
A static re-usable emptyByteProvider
instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
close()
Releases any resources theByteProvider
may have occupiedjava.lang.String
getAbsolutePath()
Returns the absolute path (similar to, but not a, URI) to theByteProvider
.java.io.File
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 java.io.InputStream
getInputStream(long index)
Returns an input stream to the underlying byte provider starting at the specified index.java.lang.String
getName()
Returns the name of theByteProvider
.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 Detail
-
EMPTY_BYTEPROVIDER
static final ByteProvider EMPTY_BYTEPROVIDER
A static re-usable emptyByteProvider
instance.
-
-
Method Detail
-
getFSRL
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.- Returns:
- The
FSRL
of the underlyingFile
, or null if no associatedFile
.
-
getFile
java.io.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
java.lang.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
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
ByteProvider
or null if not associated with aFile
.
-
length
long length() throws java.io.IOException
Returns 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.IOException
Releases any resources theByteProvider
may have occupied- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
- if an I/O error occurs
-
readByte
byte readByte(long index) throws java.io.IOException
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:
java.io.IOException
- if an I/O error occurs
-
readBytes
byte[] readBytes(long index, long length) throws java.io.IOException
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:
java.io.IOException
- if an I/O error occurs
-
getInputStream
default java.io.InputStream getInputStream(long index) throws java.io.IOException
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:
java.io.IOException
- if an I/O error occurs
-
-