Class ReaderUtils

java.lang.Object
io.agentscope.core.rag.reader.ReaderUtils

public final class ReaderUtils extends Object
Utility class for common reader operations.

This class provides shared functionality for document readers, including:

  • Document ID generation using hash algorithms
  • Byte array to hex string conversion
  • Method Details

    • generateDocId

      public static String generateDocId(String input, String algorithm)
      Generates a deterministic document ID using the specified hash algorithm.

      This method is useful for creating consistent document IDs based on file paths or other identifying information.

      Parameters:
      input - the input string to hash (typically a file path)
      algorithm - the hash algorithm to use (e.g., "MD5", "SHA-256")
      Returns:
      the hash of the input as a hexadecimal string
      Throws:
      RuntimeException - if the specified algorithm is not available
    • generateDocIdMD5

      public static String generateDocIdMD5(String input)
      Generates a deterministic document ID using MD5 hash.

      This is a convenience method that uses MD5 as the hash algorithm.

      Parameters:
      input - the input string to hash (typically a file path)
      Returns:
      MD5 hash of the input as a hexadecimal string
    • generateDocIdSHA256

      public static String generateDocIdSHA256(String input)
      Generates a deterministic document ID using SHA-256 hash.

      This is a convenience method that uses SHA-256 as the hash algorithm.

      Parameters:
      input - the input string to hash (typically a file path)
      Returns:
      SHA-256 hash of the input as a hexadecimal string
    • bytesToHex

      public static String bytesToHex(byte[] bytes)
      Converts byte array to hexadecimal string.
      Parameters:
      bytes - the byte array to convert
      Returns:
      hexadecimal string representation (lowercase)