| 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.IOException; |
| 19 | |
import java.io.Writer; |
| 20 | |
import java.util.concurrent.Callable; |
| 21 | |
|
| 22 | |
import eu.simuline.octave.exception.OctaveIOException; |
| 23 | |
|
| 24 | |
import org.apache.commons.logging.Log; |
| 25 | |
import org.apache.commons.logging.LogFactory; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | 2142 | final class OctaveWriterCallable implements Callable<Void> { |
| 32 | |
|
| 33 | 4 | private static final Log LOG = LogFactory |
| 34 | 2 | .getLog(OctaveWriterCallable.class); |
| 35 | |
|
| 36 | |
static final String EXCEPTION_MESSAGE_FUNCTOR = |
| 37 | |
"IOException from WriteFunctor"; |
| 38 | |
|
| 39 | |
static final String EXCEPTION_MESSAGE_SPACER = |
| 40 | |
"IOException when writing spacer"; |
| 41 | |
|
| 42 | |
|
| 43 | |
private final Writer processWriter; |
| 44 | |
|
| 45 | |
private final WriteFunctor writeFunctor; |
| 46 | |
|
| 47 | |
private final String spacer; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
OctaveWriterCallable(final Writer processWriter, |
| 55 | |
final WriteFunctor writeFunctor, |
| 56 | 2142 | final String spacer) { |
| 57 | 2142 | this.processWriter = processWriter; |
| 58 | 2142 | this.writeFunctor = writeFunctor; |
| 59 | 2142 | this.spacer = spacer; |
| 60 | 2142 | } |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
@Override |
| 69 | |
public Void call() { |
| 70 | |
|
| 71 | |
try { |
| 72 | 2142 | this.writeFunctor.doWrites(this.processWriter); |
| 73 | 0 | } catch (final IOException e) { |
| 74 | 0 | LOG.debug(EXCEPTION_MESSAGE_FUNCTOR, e); |
| 75 | 0 | throw new OctaveIOException(EXCEPTION_MESSAGE_FUNCTOR, e); |
| 76 | 2138 | } |
| 77 | |
try { |
| 78 | 2138 | this.processWriter.write("\nprintf(\"\\n%s\\n\", \"" + |
| 79 | |
this.spacer + "\");\n"); |
| 80 | 2138 | this.processWriter.flush(); |
| 81 | 0 | } catch (final IOException e) { |
| 82 | 0 | LOG.debug(EXCEPTION_MESSAGE_SPACER, e); |
| 83 | 0 | throw new OctaveIOException(EXCEPTION_MESSAGE_SPACER, e); |
| 84 | 2138 | } |
| 85 | 2138 | LOG.debug("Has written all"); |
| 86 | 2138 | return null; |
| 87 | |
} |
| 88 | |
|
| 89 | |
} |