Skip to content
Permalink
Browse files
BATCHEE-85 configurable fileEncoding for JSefaReaders
  • Loading branch information
struberg committed Dec 7, 2015
1 parent 4d739e9 commit f8d68fef9a9bd1f4bb293b98d44154b2b1d5679d
Showing 1 changed file with 18 additions and 2 deletions.
@@ -22,8 +22,11 @@

import javax.batch.api.BatchProperty;
import javax.inject.Inject;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.nio.charset.Charset;

public abstract class JSefaReader extends CountedReader {
@Inject
@@ -61,12 +64,25 @@ public abstract class JSefaReader extends CountedReader {
@Documentation("file to read")
protected String file;

@Inject
@BatchProperty
@Documentation("the encoding to use while reading the file. E.g. \"UTF-8\". If not specified the system default encoding is being used.")
protected String fileEncoding;

protected Deserializer deserializer;

@Override
public void open(final Serializable checkpoint) throws Exception {
deserializer = initDeserializer();
deserializer.open(new FileReader(file));

Charset charset;
if (fileEncoding != null && !fileEncoding.isEmpty()) {
charset = Charset.forName(fileEncoding);
} else {
charset = Charset.defaultCharset();
}

deserializer.open(new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)));
super.open(checkpoint);
}

0 comments on commit f8d68fe

Please sign in to comment.