| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package eu.simuline.octave.exec; |
| 17 | |
|
| 18 | |
import java.io.BufferedReader; |
| 19 | |
import java.io.IOException; |
| 20 | |
import java.io.Reader; |
| 21 | |
import java.util.concurrent.Callable; |
| 22 | |
|
| 23 | |
import eu.simuline.octave.exception.OctaveIOException; |
| 24 | |
|
| 25 | |
import org.apache.commons.logging.Log; |
| 26 | |
import org.apache.commons.logging.LogFactory; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 2142 | final class OctaveReaderCallable implements Callable<Void> { |
| 33 | |
|
| 34 | |
private static final String MSG_IOE_READ = |
| 35 | |
"IOException from ReadFunctor"; |
| 36 | |
private static final String MSG_IOE_CLS = |
| 37 | |
"IOException during close"; |
| 38 | |
|
| 39 | 4 | private static final Log LOG = LogFactory |
| 40 | 2 | .getLog(OctaveReaderCallable.class); |
| 41 | |
|
| 42 | |
|
| 43 | |
private final BufferedReader processReader; |
| 44 | |
|
| 45 | |
private final ReadFunctor readFunctor; |
| 46 | |
|
| 47 | |
private final String spacer; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
OctaveReaderCallable(final BufferedReader processReader, |
| 55 | |
final ReadFunctor readFunctor, |
| 56 | 2142 | final String spacer) { |
| 57 | 2142 | this.processReader = processReader; |
| 58 | 2142 | this.readFunctor = readFunctor; |
| 59 | 2142 | this.spacer = spacer; |
| 60 | 2142 | } |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
@Override |
| 73 | |
public Void call() { |
| 74 | 2142 | final Reader reader = new OctaveExecuteReader(this.processReader, |
| 75 | |
this.spacer); |
| 76 | |
try { |
| 77 | 2142 | this.readFunctor.doReads(reader); |
| 78 | 12 | } catch (final IOException e) { |
| 79 | 12 | LOG.debug(MSG_IOE_READ, e); |
| 80 | 12 | throw new OctaveIOException(MSG_IOE_READ, e); |
| 81 | |
} finally { |
| 82 | 16 | try { |
| 83 | 2142 | reader.close(); |
| 84 | 12 | } catch (final IOException e) { |
| 85 | 12 | LOG.debug(MSG_IOE_CLS, e); |
| 86 | 12 | throw new OctaveIOException(MSG_IOE_CLS, e); |
| 87 | 2130 | } |
| 88 | |
} |
| 89 | 2126 | return null; |
| 90 | |
} |
| 91 | |
|
| 92 | |
} |