Class ResourceUtils

java.lang.Object
org.springframework.ai.ResourceUtils

public abstract class ResourceUtils extends Object
Miscellaneous Resource utility methods. Mainly for use within Spring AI
Author:
Christian Tzolov
  • Constructor Details

    • ResourceUtils

      public ResourceUtils()
  • Method Details

    • getText

      public static String getText(String uri)
      Retrieves the content of a resource as a UTF-8 encoded string. This method uses Spring's DefaultResourceLoader to load the resource from the given URI and then reads its content as a string using UTF-8 encoding. If an IOException occurs during reading, it is wrapped in a RuntimeException.
      Parameters:
      uri - The URI of the resource to be read. This can be any URI supported by Spring's ResourceLoader, such as "classpath:", "file:", or "http:".
      Returns:
      The content of the resource as a string.
      Throws:
      RuntimeException - If an error occurs while reading the resource. This exception wraps the original IOException.