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 final class OctaveWriterCallable implements Callable<Void> {
32
33 private static final Log LOG = LogFactory
34 .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 final String spacer) {
57 this.processWriter = processWriter;
58 this.writeFunctor = writeFunctor;
59 this.spacer = spacer;
60 }
61
62
63
64
65
66
67
68 @Override
69 public Void call() {
70
71 try {
72 this.writeFunctor.doWrites(this.processWriter);
73 } catch (final IOException e) {
74 LOG.debug(EXCEPTION_MESSAGE_FUNCTOR, e);
75 throw new OctaveIOException(EXCEPTION_MESSAGE_FUNCTOR, e);
76 }
77 try {
78 this.processWriter.write("\nprintf(\"\\n%s\\n\", \"" +
79 this.spacer + "\");\n");
80 this.processWriter.flush();
81 } catch (final IOException e) {
82 LOG.debug(EXCEPTION_MESSAGE_SPACER, e);
83 throw new OctaveIOException(EXCEPTION_MESSAGE_SPACER, e);
84 }
85 LOG.debug("Has written all");
86 return null;
87 }
88
89 }