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