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`

public interface ByteProvider extends Closeable
An interface for a generic random-access byte provider.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final ByteProvider`
  `EMPTY_BYTEPROVIDER`
  A static re-usable empty `ByteProvider` instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Releases any resources the `ByteProvider` may have occupied
  `String`
  `getAbsolutePath()`
  Returns the absolute path (similar to, but not a, URI) to the `ByteProvider`.
  `File`
  `getFile()`
  Returns the underlying `File` for this `ByteProvider`, or null if this `ByteProvider` is not associated with a `File`.
  `default FSRL`
  `getFSRL()`
  Returns the `FSRL` 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.
  `String`
  `getName()`
  Returns the name of the `ByteProvider`.
  `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 the `ByteProvider`
  `byte`
  `readByte(long index)`
  Reads a byte at the specified index
  `byte[]`
  `readBytes(long index, long length)`
  Reads a byte array at the specified index

- ## Field Details

  - ### EMPTY_BYTEPROVIDER

    static final ByteProvider EMPTY_BYTEPROVIDER
    A static re-usable empty `ByteProvider` instance.

- ## Method Details

  - ### getFSRL

    default FSRL getFSRL()
    Returns the `FSRL` 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 underlying `File`, or null if no associated `File`.

  - ### getFile

    File getFile()
    Returns the underlying `File` for this `ByteProvider`, or null if this `ByteProvider` is not associated with a `File`.
    Returns:
      the underlying file for this byte provider

  - ### getName

    String getName()
    Returns the name of the `ByteProvider`. 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 the `ByteProvider`. For example, the complete path to the file.
    Returns:
      the absolute path to the `ByteProvider` or null if not associated with a `File`.

  - ### length

    long length() throws IOException
    Returns the length of the `ByteProvider`
    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

    void close() throws IOException
    Releases any resources the `ByteProvider` may have occupied
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Throws:
      `IOException` - if an I/O error occurs

  - ### readByte

    byte readByte(long index) throws 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:
      `IOException` - if an I/O error occurs

  - ### readBytes

    byte[] readBytes(long index, long length) throws IOException
    Reads a byte array at the specified index
    Parameters:
      `index` - the index of the byte to read
      `length` - the number of bytes to read
    Returns:
      the byte array read from the specified index
    Throws:
      `IOException` - if an I/O error occurs

  - ### getInputStream

    default InputStream getInputStream(long index) throws 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 the `ByteProvider` to start the `InputStream`
    Returns:
      the `InputStream`
    Throws:
      `IOException` - if an I/O error occurs