Skip to content

Commit eebbe88

Browse files
authored
Merge pull request #340 from metafacture/closeResources
Close resources.
2 parents 02091a8 + eb32306 commit eebbe88

File tree

6 files changed

+16
-14
lines changed

6 files changed

+16
-14
lines changed

metafix-web/src/main/java/org/metafacture/metafix/web/FixServlet.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.eclipse.xtext.xbase.lib.InputOutput;
1010

1111
import java.io.IOException;
12+
import java.io.Reader;
1213
import java.io.StringReader;
1314
import java.nio.file.Files;
1415
import java.nio.file.Paths;
@@ -106,7 +107,9 @@ private boolean process(final HttpServletRequest request, final HttpServletRespo
106107
}
107108

108109
private String absPathToTempFile(final String content, final String suffix) throws IOException {
109-
return FixStandaloneSetup.absPathToTempFile(new StringReader(content), suffix);
110+
try (Reader reader = new StringReader(content)) {
111+
return FixStandaloneSetup.absPathToTempFile(reader, suffix);
112+
}
110113
}
111114

112115
}

metafix/src/jmh/java/org/metafacture/metafix/MetafixBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import org.openjdk.jmh.annotations.Param;
2727

28-
import java.io.FileNotFoundException;
28+
import java.io.IOException;
2929
import java.io.UncheckedIOException;
3030

3131
public class MetafixBenchmark extends FixParseBenchmark { // checkstyle-disable-line ClassDataAbstractionCoupling
@@ -57,7 +57,7 @@ public void setup() {
5757
try {
5858
metafix = new Metafix(fixFile);
5959
}
60-
catch (final FileNotFoundException e) {
60+
catch (final IOException e) {
6161
throw new UncheckedIOException(e);
6262
}
6363

metafix/src/main/java/org/metafacture/metafix/Metafix.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.slf4j.LoggerFactory;
3232

3333
import java.io.Closeable;
34-
import java.io.FileNotFoundException;
3534
import java.io.IOException;
3635
import java.io.Reader;
3736
import java.io.StringReader;
@@ -104,19 +103,21 @@ public Metafix(final Map<String, String> newVars) {
104103
recordTransformer = null;
105104
}
106105

107-
public Metafix(final String fixDef) throws FileNotFoundException {
106+
public Metafix(final String fixDef) throws IOException {
108107
this(fixDef, NO_VARS);
109108
}
110109

111-
public Metafix(final String fixDef, final Map<String, String> vars) throws FileNotFoundException {
110+
public Metafix(final String fixDef, final Map<String, String> vars) throws IOException {
112111
init(vars);
113112

114113
if (isFixFile(fixDef)) {
115114
fixFile = fixDef;
116115
recordTransformer = getRecordTransformer(fixDef);
117116
}
118117
else {
119-
recordTransformer = getRecordTransformer(new StringReader(fixDef));
118+
try (Reader reader = new StringReader(fixDef)) {
119+
recordTransformer = getRecordTransformer(reader);
120+
}
120121
}
121122
}
122123

@@ -475,4 +476,3 @@ protected void log(final MetafactureException exception, final BiConsumer<String
475476

476477
}
477478
}
478-

metafix/src/main/java/org/metafacture/metafix/MetafixStreamAnalyzer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.metafacture.triples.TripleCount;
2828
import org.metafacture.triples.TripleSort;
2929

30-
import java.io.FileNotFoundException;
30+
import java.io.IOException;
3131

3232
/**
3333
* Superclass for Metafix-based analyzer modules based on triples (see {@link org.metafacture.framework.objects.Triple}).
@@ -49,7 +49,7 @@
4949
this.fix = new Metafix(fix);
5050
this.fix.setRepeatedFieldsToEntities(true);
5151
}
52-
catch (final FileNotFoundException e) {
52+
catch (final IOException e) {
5353
throw new MetafactureException(e);
5454
}
5555
this.countBy = countBy;

metafix/src/test/java/org/metafacture/metafix/MetafixScriptTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.mockito.Mockito;
2828
import org.mockito.junit.jupiter.MockitoExtension;
2929

30-
import java.io.FileNotFoundException;
30+
import java.io.IOException;
3131
import java.util.Arrays;
3232
import java.util.Map;
3333
import java.util.function.Consumer;
@@ -585,7 +585,7 @@ private void assertFix(final String fixDef, final Map<String, String> vars, fina
585585

586586
consumer.accept(metafix);
587587
}
588-
catch (final FileNotFoundException e) {
588+
catch (final IOException e) {
589589
throw new RuntimeException(e);
590590
}
591591
}

metafix/src/test/java/org/metafacture/metafix/MetafixTestHelpers.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.io.ByteArrayOutputStream;
2828
import java.io.File;
29-
import java.io.FileNotFoundException;
3029
import java.io.IOException;
3130
import java.io.PrintStream;
3231
import java.nio.file.Files;
@@ -152,7 +151,7 @@ private static Metafix fix(final StreamReceiver receiver, final String fix, fina
152151
metafix = new Metafix(fix, vars);
153152
metafix.setReceiver(receiver);
154153
}
155-
catch (final FileNotFoundException e) {
154+
catch (final IOException e) {
156155
e.printStackTrace();
157156
}
158157
return metafix;

0 commit comments

Comments
 (0)