2323import java .nio .file .Files ;
2424import java .nio .file .Path ;
2525
26+ /** Utility class for reading and parsing Serverless Workflow definitions from various sources. */
2627public class WorkflowReader {
2728
29+ /**
30+ * Reads a workflow from an {@link InputStream} using the specified format.
31+ *
32+ * @param input the input stream containing the workflow definition
33+ * @param format the workflow format
34+ * @return the parsed {@link Workflow}
35+ * @throws IOException if an I/O error occurs
36+ */
2837 public static Workflow readWorkflow (InputStream input , WorkflowFormat format ) throws IOException {
2938 return defaultReader ().read (input , format );
3039 }
3140
41+ /**
42+ * Reads a workflow from a {@link Reader} using the specified format.
43+ *
44+ * @param input the reader containing the workflow definition
45+ * @param format the workflow format
46+ * @return the parsed {@link Workflow}
47+ * @throws IOException if an I/O error occurs
48+ */
3249 public static Workflow readWorkflow (Reader input , WorkflowFormat format ) throws IOException {
3350 return defaultReader ().read (input , format );
3451 }
3552
53+ /**
54+ * Reads a workflow from a byte array using the specified format.
55+ *
56+ * @param input the byte array containing the workflow definition
57+ * @param format the workflow format
58+ * @return the parsed {@link Workflow}
59+ * @throws IOException if an I/O error occurs
60+ */
3661 public static Workflow readWorkflow (byte [] input , WorkflowFormat format ) throws IOException {
3762 return defaultReader ().read (input , format );
3863 }
3964
65+ /**
66+ * Reads a workflow from a file path, inferring the format from the file extension.
67+ *
68+ * @param path the path to the workflow file
69+ * @return the parsed {@link Workflow}
70+ * @throws IOException if an I/O error occurs
71+ */
4072 public static Workflow readWorkflow (Path path ) throws IOException {
4173 return readWorkflow (path , WorkflowFormat .fromPath (path ), defaultReader ());
4274 }
4375
76+ /**
77+ * Reads a workflow from a file path using the specified format.
78+ *
79+ * @param path the path to the workflow file
80+ * @param format the workflow format
81+ * @return the parsed {@link Workflow}
82+ * @throws IOException if an I/O error occurs
83+ */
4484 public static Workflow readWorkflow (Path path , WorkflowFormat format ) throws IOException {
4585 return readWorkflow (path , format , defaultReader ());
4686 }
4787
88+ /**
89+ * Reads a workflow from a string using the specified format.
90+ *
91+ * @param input the string containing the workflow definition
92+ * @param format the workflow format
93+ * @return the parsed {@link Workflow}
94+ * @throws IOException if an I/O error occurs
95+ */
4896 public static Workflow readWorkflowFromString (String input , WorkflowFormat format )
4997 throws IOException {
5098 return defaultReader ().read (input , format );
5199 }
52100
101+ /**
102+ * Reads a workflow from the classpath, inferring the format from the file name.
103+ *
104+ * @param classpath the classpath location of the workflow file
105+ * @return the parsed {@link Workflow}
106+ * @throws IOException if an I/O error occurs
107+ */
53108 public static Workflow readWorkflowFromClasspath (String classpath ) throws IOException {
54109 return readWorkflowFromClasspath (classpath , defaultReader ());
55110 }
56111
112+ /**
113+ * Reads a workflow from the classpath using the specified class loader and format.
114+ *
115+ * @param classpath the classpath location of the workflow file
116+ * @param cl the class loader to use
117+ * @param format the workflow format
118+ * @return the parsed {@link Workflow}
119+ * @throws IOException if an I/O error occurs
120+ */
57121 public static Workflow readWorkflowFromClasspath (
58122 String classpath , ClassLoader cl , WorkflowFormat format ) throws IOException {
59123 return readWorkflowFromClasspath (classpath , defaultReader ());
60124 }
61125
126+ /**
127+ * Reads a workflow from a file path using a custom reader.
128+ *
129+ * @param path the path to the workflow file
130+ * @param reader the custom {@link WorkflowReaderOperations}
131+ * @return the parsed {@link Workflow}
132+ * @throws IOException if an I/O error occurs
133+ */
62134 public static Workflow readWorkflow (Path path , WorkflowReaderOperations reader )
63135 throws IOException {
64136 return readWorkflow (path , WorkflowFormat .fromPath (path ), reader );
65137 }
66138
139+ /**
140+ * Reads a workflow from a file path using the specified format and custom reader.
141+ *
142+ * @param path the path to the workflow file
143+ * @param format the workflow format
144+ * @param reader the custom {@link WorkflowReaderOperations}
145+ * @return the parsed {@link Workflow}
146+ * @throws IOException if an I/O error occurs
147+ */
67148 public static Workflow readWorkflow (
68149 Path path , WorkflowFormat format , WorkflowReaderOperations reader ) throws IOException {
69150 return reader .read (Files .readAllBytes (path ), format );
70151 }
71152
153+ /**
154+ * Reads a workflow from the classpath using a custom reader.
155+ *
156+ * @param classpath the classpath location of the workflow file
157+ * @param reader the custom {@link WorkflowReaderOperations}
158+ * @return the parsed {@link Workflow}
159+ * @throws IOException if an I/O error occurs
160+ */
72161 public static Workflow readWorkflowFromClasspath (
73162 String classpath , WorkflowReaderOperations reader ) throws IOException {
74163 return readWorkflowFromClasspath (
@@ -78,6 +167,17 @@ public static Workflow readWorkflowFromClasspath(
78167 reader );
79168 }
80169
170+ /**
171+ * Reads a workflow from the classpath using the specified class loader, format, and custom
172+ * reader.
173+ *
174+ * @param classpath the classpath location of the workflow file
175+ * @param cl the class loader to use
176+ * @param format the workflow format
177+ * @param reader the custom {@link WorkflowReaderOperations}
178+ * @return the parsed {@link Workflow}
179+ * @throws IOException if an I/O error occurs or the resource is not found
180+ */
81181 public static Workflow readWorkflowFromClasspath (
82182 String classpath , ClassLoader cl , WorkflowFormat format , WorkflowReaderOperations reader )
83183 throws IOException {
@@ -89,10 +189,20 @@ public static Workflow readWorkflowFromClasspath(
89189 }
90190 }
91191
192+ /**
193+ * Returns a {@link WorkflowReaderOperations} instance that performs no validation.
194+ *
195+ * @return a no-validation reader
196+ */
92197 public static WorkflowReaderOperations noValidation () {
93198 return NoValidationHolder .instance ;
94199 }
95200
201+ /**
202+ * Returns a {@link WorkflowReaderOperations} instance that performs validation.
203+ *
204+ * @return a validation reader
205+ */
96206 public static WorkflowReaderOperations validation () {
97207 return ValidationHolder .instance ;
98208 }
@@ -105,6 +215,11 @@ private static class ValidationHolder {
105215 private static final WorkflowReaderOperations instance = new ValidationReader ();
106216 }
107217
218+ /**
219+ * Returns the default {@link WorkflowReaderOperations} instance (no validation).
220+ *
221+ * @return the default reader
222+ */
108223 private static WorkflowReaderOperations defaultReader () {
109224 return NoValidationHolder .instance ;
110225 }
0 commit comments