You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ko...@apache.org on 2017/10/24 08:12:39 UTC
[opennlp] branch master updated: OPENNLP-1149: remove unused member
in PlainTextByLineStream and change the type of encoding (#280)
This is an automated email from the ASF dual-hosted git repository.
koji pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/opennlp.git
The following commit(s) were added to refs/heads/master by this push:
new fca0e6e OPENNLP-1149: remove unused member in PlainTextByLineStream and change the type of encoding (#280)
fca0e6e is described below
commit fca0e6ecf6012ee47fbc92fef4533320c1e3d849
Author: Koji Sekiguchi <ko...@rondhuit.com>
AuthorDate: Tue Oct 24 17:12:37 2017 +0900
OPENNLP-1149: remove unused member in PlainTextByLineStream and change the type of encoding (#280)
OPENNLP-1149: remove unused member in PlainTextByLineStream, change the type of encoding and add null-check for inputStreamFactory
---
.../opennlp/tools/util/PlainTextByLineStream.java | 25 ++++++----------------
1 file changed, 7 insertions(+), 18 deletions(-)
diff --git a/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java b/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
index 8942437..3ac4fbc 100644
--- a/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
+++ b/opennlp-tools/src/main/java/opennlp/tools/util/PlainTextByLineStream.java
@@ -20,17 +20,15 @@ package opennlp.tools.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.nio.channels.Channels;
-import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
+import java.util.Objects;
/**
* Reads a plain text file and return each line as a <code>String</code> object.
*/
public class PlainTextByLineStream implements ObjectStream<String> {
- private final FileChannel channel;
- private final String encoding;
+ private final Charset encoding;
private InputStreamFactory inputStreamFactory;
@@ -43,9 +41,9 @@ public class PlainTextByLineStream implements ObjectStream<String> {
public PlainTextByLineStream(InputStreamFactory inputStreamFactory,
Charset charset) throws IOException {
- this.inputStreamFactory = inputStreamFactory;
- this.channel = null;
- this.encoding = charset.name();
+ this.inputStreamFactory =
+ Objects.requireNonNull(inputStreamFactory, "inputStreamFactory must not be null!");
+ this.encoding = charset;
reset();
}
@@ -56,22 +54,13 @@ public class PlainTextByLineStream implements ObjectStream<String> {
public void reset() throws IOException {
- if (inputStreamFactory != null) {
- in = new BufferedReader(new InputStreamReader(inputStreamFactory.createInputStream(),
+ in = new BufferedReader(new InputStreamReader(inputStreamFactory.createInputStream(),
encoding));
- } else if (channel == null) {
- in.reset();
- } else {
- channel.position(0);
- in = new BufferedReader(Channels.newReader(channel, encoding));
- }
}
public void close() throws IOException {
- if (in != null && channel == null) {
+ if (in != null) {
in.close();
- } else if (channel != null) {
- channel.close();
}
}
}
--
To stop receiving notification emails like this one, please contact
['"commits@opennlp.apache.org" <co...@opennlp.apache.org>'].