Read events from a binary file created with storeBinaryFile method @param nrof Maximum number of events to read @return Events in an ArrayList (empty list if didn't read any) @see #storeToBinaryFile(String, List)
(int nrof)
| 52 | * @see #storeToBinaryFile(String, List) |
| 53 | */ |
| 54 | @SuppressWarnings("unchecked") // suppress cast warnings |
| 55 | public List<ExternalEvent> readEvents(int nrof) { |
| 56 | ArrayList<ExternalEvent> events = new ArrayList<ExternalEvent>(nrof); |
| 57 | |
| 58 | if (eventsLeft == 0) { |
| 59 | return events; |
| 60 | } |
| 61 | |
| 62 | try { |
| 63 | for (int i=0; i < nrof && eventsLeft > 0; i++) { |
| 64 | events.add((ExternalEvent)in.readObject()); |
| 65 | eventsLeft--; |
| 66 | } |
| 67 | if (eventsLeft == 0) { |
| 68 | in.close(); |
| 69 | } |
| 70 | } catch (Exception e) { // FIXME: quick 'n' dirty exception handling |
| 71 | throw new SimError(e); |
| 72 | } |
| 73 | return events; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Checks if the given file is a binary external events file |
no test coverage detected