Skip to content

Commit 64a7cd4

Browse files
authored
Fix StreamSource consumption issue in createTransformer
1 parent 59ee845 commit 64a7cd4

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/main/java/org/quickfixj/codegenerator/MessageCodeGenerator.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,23 @@ private void generateComponentClasses(Task task) throws ParserConfigurationExcep
229229
private Transformer createTransformer(Task task, String xsltFile)
230230
throws TransformerFactoryConfigurationError, TransformerConfigurationException {
231231
final String cacheKey;
232-
final StreamSource styleSource;
233-
File xslt = new File(task.getTransformDirectory() + "/" + xsltFile);
232+
final File xslt = new File(task.getTransformDirectory() + "/" + xsltFile);
234233
if (xslt.exists()) {
235234
cacheKey = xslt.getAbsolutePath();
236-
styleSource = new StreamSource(xslt);
237235
} else {
238-
logInfo("Loading predefined xslt file:" + xsltFile);
239236
cacheKey = "classpath:" + xsltFile;
240-
styleSource = new StreamSource(this.getClass().getResourceAsStream(xsltFile));
241237
}
242238

243239
try {
244240
Templates templates = templatesCache.computeIfAbsent(cacheKey, k -> {
245241
try {
242+
StreamSource styleSource;
243+
if (xslt.exists()) {
244+
styleSource = new StreamSource(xslt);
245+
} else {
246+
logInfo("Loading predefined xslt file:" + xsltFile);
247+
styleSource = new StreamSource(this.getClass().getResourceAsStream(xsltFile));
248+
}
246249
return transformerFactory.newTemplates(styleSource);
247250
} catch (TransformerConfigurationException e) {
248251
throw new CodeGenerationException(e);

0 commit comments

Comments
 (0)