Skip to content

Commit

Permalink
Close readers
Browse files Browse the repository at this point in the history
  • Loading branch information
sualeh committed Nov 10, 2024
1 parent 673e33c commit e9ca2e3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,9 @@ public void warning(final SAXParseException e) throws SAXException {
failures.add(e.getMessage());
}
});
final Reader reader = new FileInputResource(testOutputFile).openNewInputReader(UTF_8);
builder.parse(new InputSource(reader));
try (final Reader reader = new FileInputResource(testOutputFile).openNewInputReader(UTF_8); ) {
builder.parse(new InputSource(reader));
}
}

private TestUtility() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,21 @@ public void execute() {
try {
final Charset inputCharset = outputOptions.getInputCharset();
final InputResource inputResource = commandOptions.getInputResource().get();
final Reader reader = inputResource.openNewInputReader(inputCharset);
final Writer writer = outputOptions.openNewOutputWriter();
try (final Reader reader = inputResource.openNewInputReader(inputCharset);
final Writer writer = outputOptions.openNewOutputWriter(); ) {

LOGGER.log(Level.CONFIG, new StringFormat("Evaluating script, %s", inputResource));
LOGGER.log(Level.CONFIG, new StringFormat("Evaluating script, %s", inputResource));

// Set up the context
final Map<String, Object> context = new HashMap<>();
context.put("title", outputOptions.getTitle());
context.put("catalog", catalog);
context.put("connection", connection);
context.put("chain", new CommandChain(this));
// Set up the context
final Map<String, Object> context = new HashMap<>();
context.put("title", outputOptions.getTitle());
context.put("catalog", catalog);
context.put("connection", connection);
context.put("chain", new CommandChain(this));

scriptExecutor.initialize(context, reader, writer);
scriptExecutor.run();
scriptExecutor.initialize(context, reader, writer);
scriptExecutor.run();
}
} catch (final Exception e) {
throw new InternalRuntimeException("Could not execute script", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@
package schemacrawler.tools.command.template;

import static us.fatehi.utility.ioresource.InputResourceUtility.createInputResource;

import java.io.Reader;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;

import schemacrawler.schemacrawler.exceptions.ConfigurationException;
import schemacrawler.schemacrawler.exceptions.ExecutionRuntimeException;
import schemacrawler.tools.options.OutputOptions;
Expand All @@ -58,11 +56,9 @@ public void execute() {
new ConfigurationException(
String.format("Mustache template not found <%s>", templateLocation)));

try {
try (final Reader reader = inputResource.openNewInputReader(StandardCharsets.UTF_8)) {
final MustacheFactory mustacheFactory = new DefaultMustacheFactory();
final Mustache mustache =
mustacheFactory.compile(
inputResource.openNewInputReader(StandardCharsets.UTF_8), templateLocation);
final Mustache mustache = mustacheFactory.compile(reader, templateLocation);

try (final Writer writer = outputOptions.openNewOutputWriter()) {
// Evaluate the template
Expand Down

0 comments on commit e9ca2e3

Please sign in to comment.