Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close resources. #340

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.eclipse.xtext.xbase.lib.InputOutput;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -106,7 +107,9 @@ private boolean process(final HttpServletRequest request, final HttpServletRespo
}

private String absPathToTempFile(final String content, final String suffix) throws IOException {
return FixStandaloneSetup.absPathToTempFile(new StringReader(content), suffix);
try (Reader reader = new StringReader(content)) {
return FixStandaloneSetup.absPathToTempFile(reader, suffix);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import org.openjdk.jmh.annotations.Param;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UncheckedIOException;

public class MetafixBenchmark extends FixParseBenchmark { // checkstyle-disable-line ClassDataAbstractionCoupling
Expand Down Expand Up @@ -57,7 +57,7 @@ public void setup() {
try {
metafix = new Metafix(fixFile);
}
catch (final FileNotFoundException e) {
catch (final IOException e) {
throw new UncheckedIOException(e);
}

Expand Down
10 changes: 5 additions & 5 deletions metafix/src/main/java/org/metafacture/metafix/Metafix.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.slf4j.LoggerFactory;

import java.io.Closeable;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
Expand Down Expand Up @@ -104,19 +103,21 @@ public Metafix(final Map<String, String> newVars) {
recordTransformer = null;
}

public Metafix(final String fixDef) throws FileNotFoundException {
public Metafix(final String fixDef) throws IOException {
this(fixDef, NO_VARS);
}

public Metafix(final String fixDef, final Map<String, String> vars) throws FileNotFoundException {
public Metafix(final String fixDef, final Map<String, String> vars) throws IOException {
init(vars);

if (isFixFile(fixDef)) {
fixFile = fixDef;
recordTransformer = getRecordTransformer(fixDef);
}
else {
recordTransformer = getRecordTransformer(new StringReader(fixDef));
try (Reader reader = new StringReader(fixDef)) {
recordTransformer = getRecordTransformer(reader);
}
}
}

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

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.metafacture.triples.TripleCount;
import org.metafacture.triples.TripleSort;

import java.io.FileNotFoundException;
import java.io.IOException;

/**
* Superclass for Metafix-based analyzer modules based on triples (see {@link org.metafacture.framework.objects.Triple}).
Expand All @@ -49,7 +49,7 @@
this.fix = new Metafix(fix);
this.fix.setRepeatedFieldsToEntities(true);
}
catch (final FileNotFoundException e) {
catch (final IOException e) {
throw new MetafactureException(e);
}
this.countBy = countBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -585,7 +585,7 @@ private void assertFix(final String fixDef, final Map<String, String> vars, fina

consumer.accept(metafix);
}
catch (final FileNotFoundException e) {
catch (final IOException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
Expand Down Expand Up @@ -152,7 +151,7 @@ private static Metafix fix(final StreamReceiver receiver, final String fix, fina
metafix = new Metafix(fix, vars);
metafix.setReceiver(receiver);
}
catch (final FileNotFoundException e) {
catch (final IOException e) {
e.printStackTrace();
}
return metafix;
Expand Down
Loading