MCPcopy Create free account
hub / github.com/akeranen/the-one / StandardEventsReader

Class StandardEventsReader

input/StandardEventsReader.java:45–235  ·  view source on GitHub ↗

External events reader for standard-format events (created e.g by the dtnsim2parser). Syntax: <time> <actionId> <msgId> <hostId> [<host2Id> [<size>] [<respSize>]] All actions (except CONNECTION) must have first four fields

Source from the content-addressed store, hash-verified

43 * </P>
44 */
45public class StandardEventsReader implements ExternalEventsReader {
46 /** Identifier of message creation event ({@value}) */
47 public static final String CREATE = "C";
48 /** Identifier of message transfer start event ({@value}) */
49 public static final String SEND = "S";
50 /** Identifier of message delivered event ({@value}) */
51 public static final String DELIVERED = "DE";
52 /** Identifier of message transfer aborted event ({@value}) */
53 public static final String ABORT = "A";
54 /** Identifier of message dropped event ({@value}) */
55 public static final String DROP = "DR";
56 /** Identifier of message removed event ({@value}) */
57 public static final String REMOVE = "R";
58 /** Identifier of connection event ({@value}) */
59 public static final String CONNECTION = "CONN";
60 /** Value identifier of connection down event ({@value}) */
61 public static final String CONNECTION_DOWN = "down";
62 /** Value identifier of connection up event ({@value}) */
63 public static final String CONNECTION_UP = "up";
64 /** Message identifier to use to refer to all messages ({@value}) */
65 public static final String ALL_MESSAGES_ID = "*";
66
67 //private Scanner scanner;
68 private BufferedReader reader;
69
70 public StandardEventsReader(File eventsFile){
71 try {
72 //this.scanner = new Scanner(eventsFile);
73 this.reader = new BufferedReader(new FileReader(eventsFile));
74 } catch (FileNotFoundException e) {
75 throw new SimError(e.getMessage(),e);
76 }
77 }
78
79
80 public List<ExternalEvent> readEvents(int nrof) {
81 ArrayList<ExternalEvent> events = new ArrayList<ExternalEvent>(nrof);
82 int eventsRead = 0;
83 // skip empty and comment lines
84 Pattern skipPattern = Pattern.compile("(#.*)|(^\\s*$)");
85
86 String line;
87 try {
88 line = this.reader.readLine();
89 } catch (IOException e1) {
90 throw new SimError("Reading from external event file failed.");
91 }
92 while (eventsRead < nrof && line != null) {
93 Scanner lineScan = new Scanner(line);
94 if (skipPattern.matcher(line).matches()) {
95 // skip empty and comment lines
96 try {
97 line = this.reader.readLine();
98 } catch (IOException e) {
99 throw new SimError("Reading from external event file " +
100 "failed.");
101 }
102 continue;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected