@Test public void readData() throws IOException { Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(new String[] { "10.171.214.81" , "fe80::1a87:96ff:fe80:1735%wlan0" , "" }); Set<InetAddress> info = reader.readData(traceFolder); assertTrue(info.contains(InetAddress.getByName("10.171.214.81"))); assertTrue(info.contains(InetAddress.getByName("fe80::1a87:96ff:fe80:1735"))); assertTrue(info.contains(InetAddress.getByName(""))); }
@Override public Set<InetAddress> readData(String directory) { String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.DEVICEINFO_FILE; Set<InetAddress> localIPAddresses = new HashSet<InetAddress>(1); if (!filereader.fileExist(filepath)) { return localIPAddresses; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read Device Info file: "+filepath); } if(lines != null){ for(String line: lines) { int index = line.indexOf('%'); try { localIPAddresses.add(InetAddress.getByName(index > 0 ? line.substring(0, index) : line)); } catch (UnknownHostException e) { LOGGER.error("failed to read ip address: "+line); } } } return localIPAddresses; }
DeviceInfoReaderImpl extends PeripheralBase implements IDeviceInfoReader { @Override public Set<InetAddress> readData(String directory) { String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.DEVICEINFO_FILE; Set<InetAddress> localIPAddresses = new HashSet<InetAddress>(1); if (!filereader.fileExist(filepath)) { return localIPAddresses; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read Device Info file: "+filepath); } if(lines != null){ for(String line: lines) { int index = line.indexOf('%'); try { localIPAddresses.add(InetAddress.getByName(index > 0 ? line.substring(0, index) : line)); } catch (UnknownHostException e) { LOGGER.error("failed to read ip address: "+line); } } } return localIPAddresses; } }
DeviceInfoReaderImpl extends PeripheralBase implements IDeviceInfoReader { @Override public Set<InetAddress> readData(String directory) { String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.DEVICEINFO_FILE; Set<InetAddress> localIPAddresses = new HashSet<InetAddress>(1); if (!filereader.fileExist(filepath)) { return localIPAddresses; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read Device Info file: "+filepath); } if(lines != null){ for(String line: lines) { int index = line.indexOf('%'); try { localIPAddresses.add(InetAddress.getByName(index > 0 ? line.substring(0, index) : line)); } catch (UnknownHostException e) { LOGGER.error("failed to read ip address: "+line); } } } return localIPAddresses; }  }
DeviceInfoReaderImpl extends PeripheralBase implements IDeviceInfoReader { @Override public Set<InetAddress> readData(String directory) { String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.DEVICEINFO_FILE; Set<InetAddress> localIPAddresses = new HashSet<InetAddress>(1); if (!filereader.fileExist(filepath)) { return localIPAddresses; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read Device Info file: "+filepath); } if(lines != null){ for(String line: lines) { int index = line.indexOf('%'); try { localIPAddresses.add(InetAddress.getByName(index > 0 ? line.substring(0, index) : line)); } catch (UnknownHostException e) { LOGGER.error("failed to read ip address: "+line); } } } return localIPAddresses; }  @Override Set<InetAddress> readData(String directory); }
DeviceInfoReaderImpl extends PeripheralBase implements IDeviceInfoReader { @Override public Set<InetAddress> readData(String directory) { String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.DEVICEINFO_FILE; Set<InetAddress> localIPAddresses = new HashSet<InetAddress>(1); if (!filereader.fileExist(filepath)) { return localIPAddresses; } String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e) { LOGGER.error("failed to read Device Info file: "+filepath); } if(lines != null){ for(String line: lines) { int index = line.indexOf('%'); try { localIPAddresses.add(InetAddress.getByName(index > 0 ? line.substring(0, index) : line)); } catch (UnknownHostException e) { LOGGER.error("failed to read ip address: "+line); } } } return localIPAddresses; }  @Override Set<InetAddress> readData(String directory);  }