2323import java .nio .file .Files ;
2424import java .nio .file .Path ;
2525
26+ /**
27+ * Utility class for reading and parsing Serverless Workflow definitions from various sources.
28+ */
2629public class WorkflowReader {
2730
31+ /**
32+ * Reads a workflow from an {@link InputStream} using the specified format.
33+ *
34+ * @param input the input stream containing the workflow definition
35+ * @param format the workflow format
36+ * @return the parsed {@link Workflow}
37+ * @throws IOException if an I/O error occurs
38+ */
2839 public static Workflow readWorkflow (InputStream input , WorkflowFormat format ) throws IOException {
2940 return defaultReader ().read (input , format );
3041 }
3142
43+ /**
44+ * Reads a workflow from a {@link Reader} using the specified format.
45+ *
46+ * @param input the reader containing the workflow definition
47+ * @param format the workflow format
48+ * @return the parsed {@link Workflow}
49+ * @throws IOException if an I/O error occurs
50+ */
3251 public static Workflow readWorkflow (Reader input , WorkflowFormat format ) throws IOException {
3352 return defaultReader ().read (input , format );
3453 }
3554
55+ /**
56+ * Reads a workflow from a byte array using the specified format.
57+ *
58+ * @param input the byte array containing the workflow definition
59+ * @param format the workflow format
60+ * @return the parsed {@link Workflow}
61+ * @throws IOException if an I/O error occurs
62+ */
3663 public static Workflow readWorkflow (byte [] input , WorkflowFormat format ) throws IOException {
3764 return defaultReader ().read (input , format );
3865 }
3966
67+ /**
68+ * Reads a workflow from a file path, inferring the format from the file extension.
69+ *
70+ * @param path the path to the workflow file
71+ * @return the parsed {@link Workflow}
72+ * @throws IOException if an I/O error occurs
73+ */
4074 public static Workflow readWorkflow (Path path ) throws IOException {
4175 return readWorkflow (path , WorkflowFormat .fromPath (path ), defaultReader ());
4276 }
4377
78+ /**
79+ * Reads a workflow from a file path using the specified format.
80+ *
81+ * @param path the path to the workflow file
82+ * @param format the workflow format
83+ * @return the parsed {@link Workflow}
84+ * @throws IOException if an I/O error occurs
85+ */
4486 public static Workflow readWorkflow (Path path , WorkflowFormat format ) throws IOException {
4587 return readWorkflow (path , format , defaultReader ());
4688 }
4789
90+ /**
91+ * Reads a workflow from a string using the specified format.
92+ *
93+ * @param input the string containing the workflow definition
94+ * @param format the workflow format
95+ * @return the parsed {@link Workflow}
96+ * @throws IOException if an I/O error occurs
97+ */
4898 public static Workflow readWorkflowFromString (String input , WorkflowFormat format )
4999 throws IOException {
50100 return defaultReader ().read (input , format );
51101 }
52102
103+ /**
104+ * Reads a workflow from the classpath, inferring the format from the file name.
105+ *
106+ * @param classpath the classpath location of the workflow file
107+ * @return the parsed {@link Workflow}
108+ * @throws IOException if an I/O error occurs
109+ */
53110 public static Workflow readWorkflowFromClasspath (String classpath ) throws IOException {
54111 return readWorkflowFromClasspath (classpath , defaultReader ());
55112 }
56113
114+ /**
115+ * Reads a workflow from the classpath using the specified class loader and format.
116+ *
117+ * @param classpath the classpath location of the workflow file
118+ * @param cl the class loader to use
119+ * @param format the workflow format
120+ * @return the parsed {@link Workflow}
121+ * @throws IOException if an I/O error occurs
122+ */
57123 public static Workflow readWorkflowFromClasspath (
58124 String classpath , ClassLoader cl , WorkflowFormat format ) throws IOException {
59125 return readWorkflowFromClasspath (classpath , defaultReader ());
60126 }
61127
128+ /**
129+ * Reads a workflow from a file path using a custom reader.
130+ *
131+ * @param path the path to the workflow file
132+ * @param reader the custom {@link WorkflowReaderOperations}
133+ * @return the parsed {@link Workflow}
134+ * @throws IOException if an I/O error occurs
135+ */
62136 public static Workflow readWorkflow (Path path , WorkflowReaderOperations reader )
63137 throws IOException {
64138 return readWorkflow (path , WorkflowFormat .fromPath (path ), reader );
65139 }
66140
141+ /**
142+ * Reads a workflow from a file path using the specified format and custom reader.
143+ *
144+ * @param path the path to the workflow file
145+ * @param format the workflow format
146+ * @param reader the custom {@link WorkflowReaderOperations}
147+ * @return the parsed {@link Workflow}
148+ * @throws IOException if an I/O error occurs
149+ */
67150 public static Workflow readWorkflow (
68151 Path path , WorkflowFormat format , WorkflowReaderOperations reader ) throws IOException {
69152 return reader .read (Files .readAllBytes (path ), format );
70153 }
71154
155+ /**
156+ * Reads a workflow from the classpath using a custom reader.
157+ *
158+ * @param classpath the classpath location of the workflow file
159+ * @param reader the custom {@link WorkflowReaderOperations}
160+ * @return the parsed {@link Workflow}
161+ * @throws IOException if an I/O error occurs
162+ */
72163 public static Workflow readWorkflowFromClasspath (
73164 String classpath , WorkflowReaderOperations reader ) throws IOException {
74165 return readWorkflowFromClasspath (
@@ -78,6 +169,16 @@ public static Workflow readWorkflowFromClasspath(
78169 reader );
79170 }
80171
172+ /**
173+ * Reads a workflow from the classpath using the specified class loader, format, and custom reader.
174+ *
175+ * @param classpath the classpath location of the workflow file
176+ * @param cl the class loader to use
177+ * @param format the workflow format
178+ * @param reader the custom {@link WorkflowReaderOperations}
179+ * @return the parsed {@link Workflow}
180+ * @throws IOException if an I/O error occurs or the resource is not found
181+ */
81182 public static Workflow readWorkflowFromClasspath (
82183 String classpath , ClassLoader cl , WorkflowFormat format , WorkflowReaderOperations reader )
83184 throws IOException {
@@ -89,10 +190,20 @@ public static Workflow readWorkflowFromClasspath(
89190 }
90191 }
91192
193+ /**
194+ * Returns a {@link WorkflowReaderOperations} instance that performs no validation.
195+ *
196+ * @return a no-validation reader
197+ */
92198 public static WorkflowReaderOperations noValidation () {
93199 return NoValidationHolder .instance ;
94200 }
95201
202+ /**
203+ * Returns a {@link WorkflowReaderOperations} instance that performs validation.
204+ *
205+ * @return a validation reader
206+ */
96207 public static WorkflowReaderOperations validation () {
97208 return ValidationHolder .instance ;
98209 }
@@ -105,6 +216,11 @@ private static class ValidationHolder {
105216 private static final WorkflowReaderOperations instance = new ValidationReader ();
106217 }
107218
219+ /**
220+ * Returns the default {@link WorkflowReaderOperations} instance (no validation).
221+ *
222+ * @return the default reader
223+ */
108224 private static WorkflowReaderOperations defaultReader () {
109225 return NoValidationHolder .instance ;
110226 }
0 commit comments