Skip to content

Commit

Permalink
Merge pull request #195 from laeubi/issue194
Browse files Browse the repository at this point in the history
Fix #194 ModelReaderSupport uses platformencoding
  • Loading branch information
mosabua committed Nov 25, 2019
2 parents 5c9ec4a + d2e1f7c commit 884c648
Showing 1 changed file with 19 additions and 25 deletions.
Expand Up @@ -7,22 +7,17 @@
*/
package org.sonatype.maven.polyglot.io;

import org.apache.maven.model.Model;
import org.apache.maven.model.io.ModelParseException;
import org.apache.maven.model.io.ModelReader;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.IOUtil;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.Map;

import org.apache.maven.model.Model;
import org.apache.maven.model.io.ModelReader;

/**
* Support for {@link ModelReader} implementations.
*
Expand All @@ -31,20 +26,19 @@
* @since 0.7
*/
public abstract class ModelReaderSupport implements ModelReader {
public Model read(final File input, final Map<String, ?> options) throws IOException {
Model model;

Reader reader = new BufferedReader(new FileReader(input));
try {
model = read(reader, options);
model.setPomFile(input);
} finally {
IOUtil.close(reader);
}
return model;
}
public Model read(final File input, final Map<String, ?> options) throws IOException {
try (FileInputStream inputStream = new FileInputStream(input)) {
Model model = read(inputStream, options);
model.setPomFile(input);
return model;
}
}

public Model read(final InputStream input, final Map<String, ?> options) throws IOException {
return read(new InputStreamReader(input), options);
}
public Model read(final InputStream input, final Map<String, ?> options) throws IOException {
return read(new InputStreamReader(input, getCharset(options)), options);
}

protected Charset getCharset(Map<String, ?> options) {
return Charset.defaultCharset();
}
}

0 comments on commit 884c648

Please sign in to comment.