stop SentenceReader when reading from InputStream and EOF is reached

Change-Id: If6ee824ca27df3fb5561c3afa0809bb624e82414
This commit is contained in:
Axel Uhl committed 2017-04-24 18:25:19 +02:00
1 parent 083c25aafd
commit 467a7d1cb1
2 files changed
+12 -2

No files matched your search

@@ -62,6 +62,10 @@ abstract class AbstractDataReader implements DataReader {
return isRunning;
}
protected void setRunning(boolean running) {
isRunning = running;
}
/**
* Read one line from the data source.
*
@@ -83,7 +87,9 @@ abstract class AbstractDataReader implements DataReader {
try {
String data = read();
if (data == null) {
Thread.sleep(SLEEP_TIME);
if (isRunning()) {
Thread.sleep(SLEEP_TIME);
}
} else if (SentenceValidator.isValid(data)) {
monitor.refresh();
Sentence s = factory.createParser(data);
@@ -52,6 +52,10 @@ class DefaultDataReader extends AbstractDataReader {
*/
@Override
public String read() throws Exception {
return input.readLine();
final String result = input.readLine();
if (result == null) {
setRunning(false);
}
return result;
}
}