@Test public void noLines() throws IOException { Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true); Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(new String[] {}); bluetoothReader.setFileReader(filereader); List<BluetoothInfo> bluetoothInfo = bluetoothReader.readData("/", 0, 0); assertTrue(bluetoothInfo.size() == 0); }
@Override public List<BluetoothInfo> readData(String directory, double startTime, double traceDuration) { List<BluetoothInfo> bluetoothInfos = new ArrayList<BluetoothInfo>(); this.activeBluetoothDuration = 0; String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BLUETOOTH_FILE; if (!filereader.fileExist(filepath)) { return bluetoothInfos; } double beginTime = 0.0; double endTime; double dLastTimeStamp = 0.0; double dActiveDuration = 0.0; BluetoothState prevBtState = null; BluetoothState btState = null; BluetoothState lastState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed reading Bluetooth info file: " + filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length == 2) { try { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime); if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_CONNECTED; } else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_DISCONNECTED; } else if (TraceDataConst.BLUETOOTH_OFF.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_TURNED_OFF; } else if (TraceDataConst.BLUETOOTH_ON.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_TURNED_ON; } else { LOGGER.warn("Unknown bluetooth state: " + firstLine); prevBtState = BluetoothState.BLUETOOTH_UNKNOWN; } lastState = prevBtState; dLastTimeStamp = beginTime; } catch (Exception e) { LOGGER.warn("Unexpected error parsing bluetooth event: " + firstLine, e); } } else { LOGGER.warn("Invalid Bluetooth trace entry: " + firstLine); } for (int i = 1; i < lines.length; i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); if (strFields.length == 2) { try { endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_CONNECTED; } else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_DISCONNECTED; } else if (TraceDataConst.BLUETOOTH_OFF.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_TURNED_OFF; } else if (TraceDataConst.BLUETOOTH_ON.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_TURNED_ON; } else { LOGGER.warn("Unknown bluetooth state: " + strLineBuf); btState = BluetoothState.BLUETOOTH_UNKNOWN; } bluetoothInfos.add(new BluetoothInfo(beginTime, endTime, prevBtState)); if (lastState == BluetoothState.BLUETOOTH_CONNECTED) { dActiveDuration += (endTime - dLastTimeStamp); } lastState = btState; dLastTimeStamp = endTime; prevBtState = btState; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error parsing bluetooth event: " + strLineBuf, e); } } else { LOGGER.warn("Invalid Bluetooth trace entry: " + strLineBuf); } } bluetoothInfos.add(new BluetoothInfo(beginTime, traceDuration, prevBtState)); if (lastState == BluetoothState.BLUETOOTH_CONNECTED) { dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp); } this.activeBluetoothDuration = dActiveDuration; } return bluetoothInfos; }
BluetoothInfoReaderImpl extends PeripheralBase implements IBluetoothInfoReader { @Override public List<BluetoothInfo> readData(String directory, double startTime, double traceDuration) { List<BluetoothInfo> bluetoothInfos = new ArrayList<BluetoothInfo>(); this.activeBluetoothDuration = 0; String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BLUETOOTH_FILE; if (!filereader.fileExist(filepath)) { return bluetoothInfos; } double beginTime = 0.0; double endTime; double dLastTimeStamp = 0.0; double dActiveDuration = 0.0; BluetoothState prevBtState = null; BluetoothState btState = null; BluetoothState lastState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed reading Bluetooth info file: " + filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length == 2) { try { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime); if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_CONNECTED; } else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_DISCONNECTED; } else if (TraceDataConst.BLUETOOTH_OFF.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_TURNED_OFF; } else if (TraceDataConst.BLUETOOTH_ON.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_TURNED_ON; } else { LOGGER.warn("Unknown bluetooth state: " + firstLine); prevBtState = BluetoothState.BLUETOOTH_UNKNOWN; } lastState = prevBtState; dLastTimeStamp = beginTime; } catch (Exception e) { LOGGER.warn("Unexpected error parsing bluetooth event: " + firstLine, e); } } else { LOGGER.warn("Invalid Bluetooth trace entry: " + firstLine); } for (int i = 1; i < lines.length; i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); if (strFields.length == 2) { try { endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_CONNECTED; } else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_DISCONNECTED; } else if (TraceDataConst.BLUETOOTH_OFF.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_TURNED_OFF; } else if (TraceDataConst.BLUETOOTH_ON.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_TURNED_ON; } else { LOGGER.warn("Unknown bluetooth state: " + strLineBuf); btState = BluetoothState.BLUETOOTH_UNKNOWN; } bluetoothInfos.add(new BluetoothInfo(beginTime, endTime, prevBtState)); if (lastState == BluetoothState.BLUETOOTH_CONNECTED) { dActiveDuration += (endTime - dLastTimeStamp); } lastState = btState; dLastTimeStamp = endTime; prevBtState = btState; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error parsing bluetooth event: " + strLineBuf, e); } } else { LOGGER.warn("Invalid Bluetooth trace entry: " + strLineBuf); } } bluetoothInfos.add(new BluetoothInfo(beginTime, traceDuration, prevBtState)); if (lastState == BluetoothState.BLUETOOTH_CONNECTED) { dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp); } this.activeBluetoothDuration = dActiveDuration; } return bluetoothInfos; } }
BluetoothInfoReaderImpl extends PeripheralBase implements IBluetoothInfoReader { @Override public List<BluetoothInfo> readData(String directory, double startTime, double traceDuration) { List<BluetoothInfo> bluetoothInfos = new ArrayList<BluetoothInfo>(); this.activeBluetoothDuration = 0; String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BLUETOOTH_FILE; if (!filereader.fileExist(filepath)) { return bluetoothInfos; } double beginTime = 0.0; double endTime; double dLastTimeStamp = 0.0; double dActiveDuration = 0.0; BluetoothState prevBtState = null; BluetoothState btState = null; BluetoothState lastState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed reading Bluetooth info file: " + filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length == 2) { try { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime); if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_CONNECTED; } else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_DISCONNECTED; } else if (TraceDataConst.BLUETOOTH_OFF.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_TURNED_OFF; } else if (TraceDataConst.BLUETOOTH_ON.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_TURNED_ON; } else { LOGGER.warn("Unknown bluetooth state: " + firstLine); prevBtState = BluetoothState.BLUETOOTH_UNKNOWN; } lastState = prevBtState; dLastTimeStamp = beginTime; } catch (Exception e) { LOGGER.warn("Unexpected error parsing bluetooth event: " + firstLine, e); } } else { LOGGER.warn("Invalid Bluetooth trace entry: " + firstLine); } for (int i = 1; i < lines.length; i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); if (strFields.length == 2) { try { endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_CONNECTED; } else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_DISCONNECTED; } else if (TraceDataConst.BLUETOOTH_OFF.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_TURNED_OFF; } else if (TraceDataConst.BLUETOOTH_ON.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_TURNED_ON; } else { LOGGER.warn("Unknown bluetooth state: " + strLineBuf); btState = BluetoothState.BLUETOOTH_UNKNOWN; } bluetoothInfos.add(new BluetoothInfo(beginTime, endTime, prevBtState)); if (lastState == BluetoothState.BLUETOOTH_CONNECTED) { dActiveDuration += (endTime - dLastTimeStamp); } lastState = btState; dLastTimeStamp = endTime; prevBtState = btState; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error parsing bluetooth event: " + strLineBuf, e); } } else { LOGGER.warn("Invalid Bluetooth trace entry: " + strLineBuf); } } bluetoothInfos.add(new BluetoothInfo(beginTime, traceDuration, prevBtState)); if (lastState == BluetoothState.BLUETOOTH_CONNECTED) { dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp); } this.activeBluetoothDuration = dActiveDuration; } return bluetoothInfos; }  }
BluetoothInfoReaderImpl extends PeripheralBase implements IBluetoothInfoReader { @Override public List<BluetoothInfo> readData(String directory, double startTime, double traceDuration) { List<BluetoothInfo> bluetoothInfos = new ArrayList<BluetoothInfo>(); this.activeBluetoothDuration = 0; String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BLUETOOTH_FILE; if (!filereader.fileExist(filepath)) { return bluetoothInfos; } double beginTime = 0.0; double endTime; double dLastTimeStamp = 0.0; double dActiveDuration = 0.0; BluetoothState prevBtState = null; BluetoothState btState = null; BluetoothState lastState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed reading Bluetooth info file: " + filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length == 2) { try { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime); if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_CONNECTED; } else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_DISCONNECTED; } else if (TraceDataConst.BLUETOOTH_OFF.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_TURNED_OFF; } else if (TraceDataConst.BLUETOOTH_ON.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_TURNED_ON; } else { LOGGER.warn("Unknown bluetooth state: " + firstLine); prevBtState = BluetoothState.BLUETOOTH_UNKNOWN; } lastState = prevBtState; dLastTimeStamp = beginTime; } catch (Exception e) { LOGGER.warn("Unexpected error parsing bluetooth event: " + firstLine, e); } } else { LOGGER.warn("Invalid Bluetooth trace entry: " + firstLine); } for (int i = 1; i < lines.length; i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); if (strFields.length == 2) { try { endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_CONNECTED; } else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_DISCONNECTED; } else if (TraceDataConst.BLUETOOTH_OFF.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_TURNED_OFF; } else if (TraceDataConst.BLUETOOTH_ON.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_TURNED_ON; } else { LOGGER.warn("Unknown bluetooth state: " + strLineBuf); btState = BluetoothState.BLUETOOTH_UNKNOWN; } bluetoothInfos.add(new BluetoothInfo(beginTime, endTime, prevBtState)); if (lastState == BluetoothState.BLUETOOTH_CONNECTED) { dActiveDuration += (endTime - dLastTimeStamp); } lastState = btState; dLastTimeStamp = endTime; prevBtState = btState; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error parsing bluetooth event: " + strLineBuf, e); } } else { LOGGER.warn("Invalid Bluetooth trace entry: " + strLineBuf); } } bluetoothInfos.add(new BluetoothInfo(beginTime, traceDuration, prevBtState)); if (lastState == BluetoothState.BLUETOOTH_CONNECTED) { dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp); } this.activeBluetoothDuration = dActiveDuration; } return bluetoothInfos; }  @Override List<BluetoothInfo> readData(String directory, double startTime, double traceDuration); @Override double getBluetoothActiveDuration(); }
BluetoothInfoReaderImpl extends PeripheralBase implements IBluetoothInfoReader { @Override public List<BluetoothInfo> readData(String directory, double startTime, double traceDuration) { List<BluetoothInfo> bluetoothInfos = new ArrayList<BluetoothInfo>(); this.activeBluetoothDuration = 0; String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BLUETOOTH_FILE; if (!filereader.fileExist(filepath)) { return bluetoothInfos; } double beginTime = 0.0; double endTime; double dLastTimeStamp = 0.0; double dActiveDuration = 0.0; BluetoothState prevBtState = null; BluetoothState btState = null; BluetoothState lastState = null; String firstLine; String strLineBuf; String[] lines = null; try { lines = filereader.readAllLine(filepath); } catch (IOException e1) { LOGGER.error("failed reading Bluetooth info file: " + filepath); } if (lines != null && lines.length > 0) { firstLine = lines[0]; String strFieldsFirstLine[] = firstLine.split(" "); if (strFieldsFirstLine.length == 2) { try { beginTime = Util.normalizeTime(Double.parseDouble(strFieldsFirstLine[0]), startTime); if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_CONNECTED; } else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_DISCONNECTED; } else if (TraceDataConst.BLUETOOTH_OFF.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_TURNED_OFF; } else if (TraceDataConst.BLUETOOTH_ON.equals(strFieldsFirstLine[1])) { prevBtState = BluetoothState.BLUETOOTH_TURNED_ON; } else { LOGGER.warn("Unknown bluetooth state: " + firstLine); prevBtState = BluetoothState.BLUETOOTH_UNKNOWN; } lastState = prevBtState; dLastTimeStamp = beginTime; } catch (Exception e) { LOGGER.warn("Unexpected error parsing bluetooth event: " + firstLine, e); } } else { LOGGER.warn("Invalid Bluetooth trace entry: " + firstLine); } for (int i = 1; i < lines.length; i++) { strLineBuf = lines[i]; String strFields[] = strLineBuf.split(" "); if (strFields.length == 2) { try { endTime = Util.normalizeTime(Double.parseDouble(strFields[0]), startTime); if (TraceDataConst.BLUETOOTH_CONNECTED.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_CONNECTED; } else if (TraceDataConst.BLUETOOTH_DISCONNECTED.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_DISCONNECTED; } else if (TraceDataConst.BLUETOOTH_OFF.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_TURNED_OFF; } else if (TraceDataConst.BLUETOOTH_ON.equals(strFields[1])) { btState = BluetoothState.BLUETOOTH_TURNED_ON; } else { LOGGER.warn("Unknown bluetooth state: " + strLineBuf); btState = BluetoothState.BLUETOOTH_UNKNOWN; } bluetoothInfos.add(new BluetoothInfo(beginTime, endTime, prevBtState)); if (lastState == BluetoothState.BLUETOOTH_CONNECTED) { dActiveDuration += (endTime - dLastTimeStamp); } lastState = btState; dLastTimeStamp = endTime; prevBtState = btState; beginTime = endTime; } catch (Exception e) { LOGGER.warn("Unexpected error parsing bluetooth event: " + strLineBuf, e); } } else { LOGGER.warn("Invalid Bluetooth trace entry: " + strLineBuf); } } bluetoothInfos.add(new BluetoothInfo(beginTime, traceDuration, prevBtState)); if (lastState == BluetoothState.BLUETOOTH_CONNECTED) { dActiveDuration += Math.max(0, traceDuration - dLastTimeStamp); } this.activeBluetoothDuration = dActiveDuration; } return bluetoothInfos; }  @Override List<BluetoothInfo> readData(String directory, double startTime, double traceDuration); @Override double getBluetoothActiveDuration();  }