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 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 private static final Log LOG = LogFactory
40 .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 final String spacer) {
57 this.processReader = processReader;
58 this.readFunctor = readFunctor;
59 this.spacer = spacer;
60 }
61
62
63
64
65
66
67
68
69
70
71
72 @Override
73 public Void call() {
74 final Reader reader = new OctaveExecuteReader(this.processReader,
75 this.spacer);
76 try {
77 this.readFunctor.doReads(reader);
78 } catch (final IOException e) {
79 LOG.debug(MSG_IOE_READ, e);
80 throw new OctaveIOException(MSG_IOE_READ, e);
81 } finally {
82 try {
83 reader.close();
84 } catch (final IOException e) {
85 LOG.debug(MSG_IOE_CLS, e);
86 throw new OctaveIOException(MSG_IOE_CLS, e);
87 }
88 }
89 return null;
90 }
91
92 }