23
23
import java .nio .file .Files ;
24
24
import java .nio .file .Path ;
25
25
26
+ /** Utility class for reading and parsing Serverless Workflow definitions from various sources. */
26
27
public class WorkflowReader {
27
28
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
+ */
28
37
public static Workflow readWorkflow (InputStream input , WorkflowFormat format ) throws IOException {
29
38
return defaultReader ().read (input , format );
30
39
}
31
40
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
+ */
32
49
public static Workflow readWorkflow (Reader input , WorkflowFormat format ) throws IOException {
33
50
return defaultReader ().read (input , format );
34
51
}
35
52
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
+ */
36
61
public static Workflow readWorkflow (byte [] input , WorkflowFormat format ) throws IOException {
37
62
return defaultReader ().read (input , format );
38
63
}
39
64
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
+ */
40
72
public static Workflow readWorkflow (Path path ) throws IOException {
41
73
return readWorkflow (path , WorkflowFormat .fromPath (path ), defaultReader ());
42
74
}
43
75
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
+ */
44
84
public static Workflow readWorkflow (Path path , WorkflowFormat format ) throws IOException {
45
85
return readWorkflow (path , format , defaultReader ());
46
86
}
47
87
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
+ */
48
96
public static Workflow readWorkflowFromString (String input , WorkflowFormat format )
49
97
throws IOException {
50
98
return defaultReader ().read (input , format );
51
99
}
52
100
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
+ */
53
108
public static Workflow readWorkflowFromClasspath (String classpath ) throws IOException {
54
109
return readWorkflowFromClasspath (classpath , defaultReader ());
55
110
}
56
111
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
+ */
57
121
public static Workflow readWorkflowFromClasspath (
58
122
String classpath , ClassLoader cl , WorkflowFormat format ) throws IOException {
59
123
return readWorkflowFromClasspath (classpath , defaultReader ());
60
124
}
61
125
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
+ */
62
134
public static Workflow readWorkflow (Path path , WorkflowReaderOperations reader )
63
135
throws IOException {
64
136
return readWorkflow (path , WorkflowFormat .fromPath (path ), reader );
65
137
}
66
138
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
+ */
67
148
public static Workflow readWorkflow (
68
149
Path path , WorkflowFormat format , WorkflowReaderOperations reader ) throws IOException {
69
150
return reader .read (Files .readAllBytes (path ), format );
70
151
}
71
152
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
+ */
72
161
public static Workflow readWorkflowFromClasspath (
73
162
String classpath , WorkflowReaderOperations reader ) throws IOException {
74
163
return readWorkflowFromClasspath (
@@ -78,6 +167,17 @@ public static Workflow readWorkflowFromClasspath(
78
167
reader );
79
168
}
80
169
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
+ */
81
181
public static Workflow readWorkflowFromClasspath (
82
182
String classpath , ClassLoader cl , WorkflowFormat format , WorkflowReaderOperations reader )
83
183
throws IOException {
@@ -89,10 +189,20 @@ public static Workflow readWorkflowFromClasspath(
89
189
}
90
190
}
91
191
192
+ /**
193
+ * Returns a {@link WorkflowReaderOperations} instance that performs no validation.
194
+ *
195
+ * @return a no-validation reader
196
+ */
92
197
public static WorkflowReaderOperations noValidation () {
93
198
return NoValidationHolder .instance ;
94
199
}
95
200
201
+ /**
202
+ * Returns a {@link WorkflowReaderOperations} instance that performs validation.
203
+ *
204
+ * @return a validation reader
205
+ */
96
206
public static WorkflowReaderOperations validation () {
97
207
return ValidationHolder .instance ;
98
208
}
@@ -105,6 +215,11 @@ private static class ValidationHolder {
105
215
private static final WorkflowReaderOperations instance = new ValidationReader ();
106
216
}
107
217
218
+ /**
219
+ * Returns the default {@link WorkflowReaderOperations} instance (no validation).
220
+ *
221
+ * @return the default reader
222
+ */
108
223
private static WorkflowReaderOperations defaultReader () {
109
224
return NoValidationHolder .instance ;
110
225
}
0 commit comments