Package org.iam.utils
Class PolicyParser
java.lang.Object
org.iam.utils.PolicyParser
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InputStreamgetTestFile(String fileName) Retrieves a test file as an input stream.static PolicyParses a JSON file into a Policy object.static PolicyparseInput(InputStream inputStream) Parses an input stream containing JSON data into a Policy object.static StringConverts a Policy object to a pretty - printed JSON string.
-
Constructor Details
-
PolicyParser
public PolicyParser()
-
-
Method Details
-
parseFile
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
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
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
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.
-