@Ignore @Test(expected=Exception.class) public void readData_FailedToParse() throws IOException { Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(new String[] { "1.487031029351E9 47.794dummy3242 -122.2030202 Loction network", }); List<LocationEvent> listLocationEvent = traceDataReader.readData(traceFolder, 0.0); assertEquals(0, listLocationEvent.size(), 0); }
@Override public List<LocationEvent> readData(String directory, double startTime) { List<LocationEvent> locationEvents = new ArrayList<LocationEvent>(); String filePath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.LOCATION_FILE; if (!filereader.fileExist(filePath)) { return locationEvents; } String[] contents = null; try { contents = filereader.readAllLine(filePath); } catch (IOException e) { LOGGER.error("failed to read user event file: " + filePath); } if(contents != null && contents.length > 0){ for (String contentBuf : contents) { if (contentBuf.trim().isEmpty()) { continue; } String splitContents[] = contentBuf.split(" "); if (splitContents.length <= 1) { LOGGER.warn("Found invalid event entry: " + contentBuf); continue; } double timeStamp = Double.parseDouble(splitContents[0]); if (timeStamp > 1.0e9) { timeStamp = Util.normalizeTime(timeStamp, startTime); } double latitude = 0; double longitude = 0; String provider = ""; StringBuffer locality = new StringBuffer(); if (splitContents.length >= 4) { try { latitude = Double.parseDouble(splitContents[1]); longitude = Double.parseDouble(splitContents[2]); provider = splitContents[3]; for (int idx = 4; idx <= (splitContents.length - 1); idx++) { if (locality.length() > 0) { locality.append(' '); } locality.append(splitContents[idx]); } locationEvents .add(new LocationEvent(timeStamp, latitude, longitude, provider, locality.toString())); } catch (Exception e) { LOGGER.warn("Found invalid event entry: " + contentBuf); continue; } } } } return locationEvents; }
LocationReaderImpl extends PeripheralBase implements LocationReader { @Override public List<LocationEvent> readData(String directory, double startTime) { List<LocationEvent> locationEvents = new ArrayList<LocationEvent>(); String filePath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.LOCATION_FILE; if (!filereader.fileExist(filePath)) { return locationEvents; } String[] contents = null; try { contents = filereader.readAllLine(filePath); } catch (IOException e) { LOGGER.error("failed to read user event file: " + filePath); } if(contents != null && contents.length > 0){ for (String contentBuf : contents) { if (contentBuf.trim().isEmpty()) { continue; } String splitContents[] = contentBuf.split(" "); if (splitContents.length <= 1) { LOGGER.warn("Found invalid event entry: " + contentBuf); continue; } double timeStamp = Double.parseDouble(splitContents[0]); if (timeStamp > 1.0e9) { timeStamp = Util.normalizeTime(timeStamp, startTime); } double latitude = 0; double longitude = 0; String provider = ""; StringBuffer locality = new StringBuffer(); if (splitContents.length >= 4) { try { latitude = Double.parseDouble(splitContents[1]); longitude = Double.parseDouble(splitContents[2]); provider = splitContents[3]; for (int idx = 4; idx <= (splitContents.length - 1); idx++) { if (locality.length() > 0) { locality.append(' '); } locality.append(splitContents[idx]); } locationEvents .add(new LocationEvent(timeStamp, latitude, longitude, provider, locality.toString())); } catch (Exception e) { LOGGER.warn("Found invalid event entry: " + contentBuf); continue; } } } } return locationEvents; } }
LocationReaderImpl extends PeripheralBase implements LocationReader { @Override public List<LocationEvent> readData(String directory, double startTime) { List<LocationEvent> locationEvents = new ArrayList<LocationEvent>(); String filePath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.LOCATION_FILE; if (!filereader.fileExist(filePath)) { return locationEvents; } String[] contents = null; try { contents = filereader.readAllLine(filePath); } catch (IOException e) { LOGGER.error("failed to read user event file: " + filePath); } if(contents != null && contents.length > 0){ for (String contentBuf : contents) { if (contentBuf.trim().isEmpty()) { continue; } String splitContents[] = contentBuf.split(" "); if (splitContents.length <= 1) { LOGGER.warn("Found invalid event entry: " + contentBuf); continue; } double timeStamp = Double.parseDouble(splitContents[0]); if (timeStamp > 1.0e9) { timeStamp = Util.normalizeTime(timeStamp, startTime); } double latitude = 0; double longitude = 0; String provider = ""; StringBuffer locality = new StringBuffer(); if (splitContents.length >= 4) { try { latitude = Double.parseDouble(splitContents[1]); longitude = Double.parseDouble(splitContents[2]); provider = splitContents[3]; for (int idx = 4; idx <= (splitContents.length - 1); idx++) { if (locality.length() > 0) { locality.append(' '); } locality.append(splitContents[idx]); } locationEvents .add(new LocationEvent(timeStamp, latitude, longitude, provider, locality.toString())); } catch (Exception e) { LOGGER.warn("Found invalid event entry: " + contentBuf); continue; } } } } return locationEvents; }  }
LocationReaderImpl extends PeripheralBase implements LocationReader { @Override public List<LocationEvent> readData(String directory, double startTime) { List<LocationEvent> locationEvents = new ArrayList<LocationEvent>(); String filePath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.LOCATION_FILE; if (!filereader.fileExist(filePath)) { return locationEvents; } String[] contents = null; try { contents = filereader.readAllLine(filePath); } catch (IOException e) { LOGGER.error("failed to read user event file: " + filePath); } if(contents != null && contents.length > 0){ for (String contentBuf : contents) { if (contentBuf.trim().isEmpty()) { continue; } String splitContents[] = contentBuf.split(" "); if (splitContents.length <= 1) { LOGGER.warn("Found invalid event entry: " + contentBuf); continue; } double timeStamp = Double.parseDouble(splitContents[0]); if (timeStamp > 1.0e9) { timeStamp = Util.normalizeTime(timeStamp, startTime); } double latitude = 0; double longitude = 0; String provider = ""; StringBuffer locality = new StringBuffer(); if (splitContents.length >= 4) { try { latitude = Double.parseDouble(splitContents[1]); longitude = Double.parseDouble(splitContents[2]); provider = splitContents[3]; for (int idx = 4; idx <= (splitContents.length - 1); idx++) { if (locality.length() > 0) { locality.append(' '); } locality.append(splitContents[idx]); } locationEvents .add(new LocationEvent(timeStamp, latitude, longitude, provider, locality.toString())); } catch (Exception e) { LOGGER.warn("Found invalid event entry: " + contentBuf); continue; } } } } return locationEvents; }  @Override List<LocationEvent> readData(String directory, double startTime); }
LocationReaderImpl extends PeripheralBase implements LocationReader { @Override public List<LocationEvent> readData(String directory, double startTime) { List<LocationEvent> locationEvents = new ArrayList<LocationEvent>(); String filePath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.LOCATION_FILE; if (!filereader.fileExist(filePath)) { return locationEvents; } String[] contents = null; try { contents = filereader.readAllLine(filePath); } catch (IOException e) { LOGGER.error("failed to read user event file: " + filePath); } if(contents != null && contents.length > 0){ for (String contentBuf : contents) { if (contentBuf.trim().isEmpty()) { continue; } String splitContents[] = contentBuf.split(" "); if (splitContents.length <= 1) { LOGGER.warn("Found invalid event entry: " + contentBuf); continue; } double timeStamp = Double.parseDouble(splitContents[0]); if (timeStamp > 1.0e9) { timeStamp = Util.normalizeTime(timeStamp, startTime); } double latitude = 0; double longitude = 0; String provider = ""; StringBuffer locality = new StringBuffer(); if (splitContents.length >= 4) { try { latitude = Double.parseDouble(splitContents[1]); longitude = Double.parseDouble(splitContents[2]); provider = splitContents[3]; for (int idx = 4; idx <= (splitContents.length - 1); idx++) { if (locality.length() > 0) { locality.append(' '); } locality.append(splitContents[idx]); } locationEvents .add(new LocationEvent(timeStamp, latitude, longitude, provider, locality.toString())); } catch (Exception e) { LOGGER.warn("Found invalid event entry: " + contentBuf); continue; } } } } return locationEvents; }  @Override List<LocationEvent> readData(String directory, double startTime);  }