Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwinter committed Jan 25, 2024
1 parent 02091a8 commit eb32306
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
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);
}
}

}
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
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

}
}

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
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
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

0 comments on commit eb32306

Please sign in to comment.