FileLogDataStore extends AbstractMemoryLogStore implements LogDataStore { @Override public void add(LogData... logDatas) { ObjectOutputStream oout = null; ByteArrayOutputStream byteArrayOutputStream = null; Arrays.sort(logDatas, logDataTimeComparator); try { HashMap<Integer, Long> newLogDataPosition = new HashMap<>(logDatas.length); long length = randomAccessFile.length(); LOGGER.trace(String.format("Setting position in file %s to %d", randomAccessFile.getFD().toString(), length)); randomAccessFile.seek(length); for (LogData logData1 : logDatas) { byteArrayOutputStream = new ByteArrayOutputStream(); oout = new ObjectOutputStream(byteArrayOutputStream); logData1.setId(getNextLogId()); int logDataId = logData1.getId(); long positionInFile = randomAccessFile.length(); oout.writeObject(logData1); oout.flush(); randomAccessFile.writeInt(byteArrayOutputStream.size()); randomAccessFile.write(byteArrayOutputStream.toByteArray()); newLogDataPosition.put(Integer.valueOf(logDataId), Long.valueOf(positionInFile)); marks.put(Integer.valueOf(logDataId), logData1.isMarked()); marksColor.put(Integer.valueOf(logDataId), logData1.getMarkerColors()); if (logData1.getNote() != null) { notable.addNoteToRow(logDataId, logData1.getNote()); } } storeIdFilePositionMapping.putAll(newLogDataPosition); for (LogData logData : logDatas) { if (logDatasId.size() == 0 || logData.getDate().compareTo(logDatasId.get(logDatasId.size() - 1).date) >= 0) { logDatasId.add(new IdAndDate(Integer.valueOf(logData.getId()), logData.getDate())); } else { int index = getIndexToInsert(logData.getDate(), 0, logDatasId.size() - 1, logDatasId.size() / 2); logDatasId.add(index, new IdAndDate(Integer.valueOf(logData.getId()), logData.getDate())); } } ensureLimit(); } catch (IOException e) { LOGGER.error(String.format("Error adding %d events: %s", logDatas.length, e.getMessage())); } finally { IOUtils.closeQuietly(oout); } } FileLogDataStore(); @Override Iterator<LogData> iterator(); @Override int getCount(); @Override void add(LogData... logDatas); @Override void remove(int... rows); @Override LogData getLogData(int row); @Override Integer getLogDataIdInRow(int row); @Override LogData[] getLogData(); @Override int clear(); void addNoteToRow(int row, Note note); Note getNote(int row); Note removeNote(int row); void removeNote(int row, boolean notify); void clearNotes(); TreeMap<Integer, Note> getAllNotes(); @Override boolean isMarked(int row); @Override MarkerColors getMarkerColors(int row); @Override void markRows(MarkerColors markerColor, int... rows); @Override void unmarkRows(int... rows);  }
@Test public void testIterator2() throws IOException { dataStore.add(logDatas); ArrayList<LogData> acutal = new ArrayList<>(); for (LogData ld : dataStore) { acutal.add(ld); } assertArrayEquals(logDatas, acutal.toArray(new LogData[acutal.size()])); }
@Test public void testAdd() throws IOException { dataStore.add(logDatas); int count = dataStore.getCount(); assertEquals(logDatas.length, count); }