public static Device parse(String src) throws ParseException { Device vo = null; if (src == null || src.isEmpty()) { throw new ParseException("unable to parse empty string", 0); } if (DEVICE_PATTERN.matcher(src).matches() == true) { vo = new Device(); String[] values = src.split("\\t"); vo.setAppkey(values[0].trim()); vo.setDevice(values[1].trim()); try { vo.setUsercount(Long.parseLong(values[2].trim())); vo.setSessioncount(Long.parseLong(values[3].trim())); } catch (NumberFormatException e) { throw new ParseException("invalid number value", 0); } } else { throw new ParseException("invalid pattern string", 0); } return vo; }
public List<String> getAppkeyResults() throws IOException { String uri = this.resultUri; List<String> list = new ArrayList<String>(); FileInputStream fstream = null; DataInputStream in = null; BufferedReader br = null; try { fstream = new FileInputStream(uri); in = new DataInputStream(fstream); br = new BufferedReader(new InputStreamReader(in)); Set<String> appKeys = new HashSet<String>(); String line; while ((line = br.readLine()) != null) { line = line.trim(); if (line.isEmpty()) continue; try { Device src = DeviceResultParser.parse(line); if (src != null && appKeys.contains(src.getAppkey()) == false) { list.add(src.getAppkey()); appKeys.add(src.getAppkey()); } } catch (ParseException ignore) { continue; } } } catch (FileNotFoundException ignore) {; } catch (IOException ioe) { throw ioe; } finally { if (br != null) br.close(); if (in != null) in.close(); if (fstream != null) fstream.close(); } return list; }
public static void main(String[] args) throws IOException { FingraphConfig config = new FingraphConfig(); TargetDate target = ArgsOptionUtil.getTargetDate("day", "2014-08-20"); DeviceReader reader = new DeviceReader(config, target); List<Device> list = reader.getDeviceResults("fin278318"); for (Device vo : list) { System.out.println(vo.toString()); } System.out.println("--------------------"); target = ArgsOptionUtil.getTargetDate("week", "2014-34"); reader = new DeviceReader(config, target); list = reader.getDeviceResults("fin278318"); for (Device vo : list) { System.out.println(vo.toString()); } System.out.println("--------------------"); target = ArgsOptionUtil.getTargetDate("month", "2014-08"); reader = new DeviceReader(config, target); list = reader.getDeviceResults("fin278318"); for (Device vo : list) { System.out.println(vo.toString()); } System.exit(0); }
public List<Device> getDeviceResults(String appkey) throws IOException { String uri = this.resultUri; List<Device> list = new ArrayList<Device>(); FileInputStream fstream = null; DataInputStream in = null; BufferedReader br = null; try { fstream = new FileInputStream(uri); in = new DataInputStream(fstream); br = new BufferedReader(new InputStreamReader(in)); String line; while ((line = br.readLine()) != null) { line = line.trim(); if (line.isEmpty()) continue; try { Device vo = DeviceResultParser.parse(line); if (vo != null && vo.getAppkey().equals(appkey)) { vo.setYear(this.year); vo.setMonth(this.month); vo.setDay(this.day); vo.setHour(this.hour); vo.setWeek(this.getWeek()); vo.setDate(this.date); vo.setDatehour(this.datehour); vo.setDayofweek(this.dayofweek); vo.setFromdate(this.fromdate); vo.setTodate(this.todate); list.add(vo); } } catch (ParseException ignore) { continue; } } } catch (FileNotFoundException ignore) {; } catch (IOException ioe) { throw ioe; } finally { if (br != null) br.close(); if (in != null) in.close(); if (fstream != null) fstream.close(); } return list; }