Package org.iam.utils

Class PolicyParser

java.lang.Object
org.iam.utils.PolicyParser

public class PolicyParser extends Object
The PolicyParser class provides utility methods for parsing policy files and input streams into Policy objects, converting Policy objects to JSON strings, and retrieving test files as input streams. It uses the Jackson library for JSON processing.
Since:
2025-02-28
Author:
  • Constructor Details

    • PolicyParser

      public PolicyParser()
  • Method Details

    • parseFile

      public static Policy parseFile(Path filePath)
      Parses a JSON file into a Policy object.
      Parameters:
      filePath - The path of the JSON file to be parsed.
      Returns:
      A Policy object representing the parsed policy, or null if the file does not exist or an error occurs.
    • parseInput

      public static Policy parseInput(InputStream inputStream)
      Parses an input stream containing JSON data into a Policy object.
      Parameters:
      inputStream - The input stream containing JSON data representing the policy.
      Returns:
      A Policy object representing the parsed policy, or null if an error occurs.
    • toString

      public static String toString(Policy policy)
      Converts a Policy object to a pretty - printed JSON string.
      Parameters:
      policy - The Policy object to be converted to a JSON string.
      Returns:
      A pretty - printed JSON string representing the Policy object, or an empty string if an error occurs.
    • getTestFile

      public static InputStream getTestFile(String fileName)
      Retrieves a test file as an input stream.
      Parameters:
      fileName - The name of the test file to retrieve.
      Returns:
      An input stream representing the test file.
      Throws:
      NullPointerException - if the resource is not found.