public static void test(String[] args) {
    FileHandle filehandle = new FileHandle();
    Map<String, ErrorFile> mapfiles = filehandle.copyFile("d:\\home", "d:\\bak");
    java.util.Iterator<ErrorFile> files = mapfiles.values().iterator();

    while (files.hasNext()) {
      ErrorFile file = files.next();
      System.out.println(
          file.getDestfile().getName() + ",,," + file.getSgsnid() + ",,," + file.getSrcfilename());
    }
  }
示例#2
0
  // Opens/creates a coordinate file with the given name
  public CoordFile(Context context, String filename) {
    mContext = context;
    Filename = filename;

    if (Filename == null) {
      Filename =
          String.format("CoordLog_%s.txt", DateStrings.GetDateTimeString(Calendar.getInstance()));
    }

    try {
      mFile = new File(filename);
      boolean exists = mFile.exists();

      mWriter = new FileWriter(filename, true);

      if (exists) {
        ReadFile();
      } else {
        String entry = "Date,Ticks,Longitude,Latitude,Altitude,Accuracy,Bearing,Speed\n";
        mWriter.append(entry);

        Toast t =
            Toast.makeText(
                mContext, String.format("Created output file %s", filename), Toast.LENGTH_SHORT);
        t.show();
      }
    } catch (Exception e) {
      ErrorFile.WriteException(e, context);
    }
  }
示例#3
0
  private void ReadFile() {
    long ticks = 0;
    try {
      BufferedReader br = new BufferedReader(new FileReader(mFile));
      char[] buf = new char[(int) mFile.length()];
      br.read(buf, 0, (int) mFile.length());
      br.close();
      String text = String.copyValueOf(buf);

      String[] lines = text.split("\n");

      mCoords.clear();
      for (int i = 0; i < lines.length; i++) {
        String[] parts = lines[i].split(",");
        if (parts.length < 8) continue;

        if (parts[0].trim().equals("Date")) continue;

        Location location = new Location("File");
        int strength = 0;
        try {
          ticks = Long.parseLong(parts[1].trim());
          location.setTime(ticks);

          location.setLongitude(Double.parseDouble(parts[2].trim()));
          location.setLatitude(Double.parseDouble(parts[3].trim()));
          location.setAltitude(Double.parseDouble(parts[4].trim()));
          location.setAccuracy(Float.parseFloat(parts[5].trim()));
          location.setBearing(Float.parseFloat(parts[6].trim()));
          location.setSpeed(Float.parseFloat(parts[7].trim()));
          strength = Integer.parseInt(parts[8].trim());
        } catch (Exception e) {
          ErrorFile.WriteException(e, null);
        }

        mCoords.add(new GPSCoordinate(location, strength));
      }
    } catch (Exception e) {
      ErrorFile.WriteException(e, mContext);
    }
  }
示例#4
0
  public void WriteEntry(Location location, int strength) {
    if (mClosing) return;

    mWriting = true;
    try {
      GPSCoordinate coord = new GPSCoordinate(location, strength);

      mCoords.add(coord);

      mWriter.append(coord.ToString() + ", " + strength + "\n");

      // Toast t = Toast.makeText(mContext, "Wrote log entry", Toast.LENGTH_SHORT);
      // t.show();
    } catch (Exception e) {
      ErrorFile.WriteException(e, mContext);
    }
    mWriting = false;
  }
示例#5
0
  public void Close() {
    mClosing = true;
    if (mWriter != null) {
      for (int i = 0; i < 10; i++) {
        if (!mWriting) break;
        try {
          Thread.sleep(100);
        } catch (Exception e) {
        }
      }

      try {
        mWriter.close();
      } catch (Exception e) {
        ErrorFile.WriteException(e, mContext);
      }
      mWriter = null;
    }
  }
  /**
   *
   *
   * <pre>
   * 处理流程:
   * 1.到原目录下copy所有文件到某个目录下,每天1个目录,记录下这些个文件copy后的路径
   * 2.上面copy文件的时候,以休息100毫秒的形式判断这个文件是否有改动,如果有,记录下来,处理完其他的后再处理这个
   * 3.copy过后的文件名,将之前文件所在的目录带入,同时加入此次处理的时间戳
   * 4.处理之前,判断原文件名+sgsn号是否已经处理过,如果处理过,拿到行数后忽略掉,否则从0开始
   * 5.处理完毕后,将之前的都删掉,将处理过的都入库,字段为id,sgsnid,filename,System.currentMillis()
   * 6.处理时间定为每10分钟1次
   * 7.先通过crontab的方式执行
   *
   * </pre>
   *
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) {
    Connection con = null;
    System.out.println("============================================================");
    long begin = System.currentTimeMillis();

    String today = args[0]; // 对应的目录
    String flag = args[1]; // 此次的标志

    System.out.println(today + "======" + flag);

    try {
      //			init();
      HWChrFileHandle filehandle = new HWChrFileHandle();

      String destdir = "/export/home1/GPRS/JAVABIN/files/chrdest/hw" + today;

      Map<String, ErrorFile> mapfiles = filehandle.getHWFile(destdir, flag);
      System.out.println("本次获取的文件个数为:::" + mapfiles.size());
      con = DBUtils.getOracleCon();
      System.out.println("成功获取到数据库连接OK");
      System.out.println("mapfiles.size():" + mapfiles.size());

      int weekday = getWeekOfDay(); // 今天星期几
      int thehour = getNowHour(); // 现在几点
      String thedate = getNowDate(); // 今天哪天
      if (thehour
          == 0) { // 如果现在是0点的话,则数据都入库到昨天的表里面,同时要清掉上周今天的数据,并同时统计好今天的按天数据,即group by
                  // sgsnid,kuang,cao,flowid的总数
        weekday = getYestardayWeekOfDay(); // 0点跑的程序,插入到昨天的数据里面去
        // 这里要清掉表的数据
        int _today = getWeekOfDay();
        String deleteTable = "hwchr_log_" + _today; // truncate 掉这个table
        filehandle.truncateTable(deleteTable); // 执行truncate..同时这里要统计当天的所有程序数据
        thehour = 23;
        thedate = getYestardayDate();
        filehandle.statFlowidDay(con, thedate); // 统计一天的数据情况

      } else {
        thehour = thehour - 1; // 统计的都是前1个小时的数据啊
      }

      System.out.println("时间:" + thehour + ",日期:" + thedate + ",星期:" + weekday);

      if (mapfiles.size() > 0) {

        ReadHandleHistory readHistory = new ReadHandleHistory(con);
        //				readHistory.getFromDB(mapfiles);
        readHistory.getFromCHRDB(mapfiles);
        long now = System.currentTimeMillis();
        java.util.Iterator<ErrorFile> files = mapfiles.values().iterator();
        List<HWChrLog> cdrs = null;
        while (files.hasNext()) {

          ErrorFile file = files.next();
          cdrs = filehandle.parseHWChrFile(file);

          System.out.println(df.format(new Date()) + "=>cdrs.size():::" + cdrs.size());

          filehandle.saveHWChr(con, cdrs, weekday, thehour, thedate);

          System.out.println(
              "解析并存储"
                  + file.getSgsnid()
                  + "_"
                  + file.getSrcfilename()
                  + "所花时间:"
                  + (System.currentTimeMillis() - now));
          now = System.currentTimeMillis();
        }

        // 然后这里入库,也就是数据
        readHistory.saveLatestErrors(mapfiles);

        filehandle.saveFlowidHourDatas(con, thedate, thehour);
        filehandle.saveFlowidErrorHourDatas(con, thedate, thehour);
        System.out.println("所有文件处理完毕!!!" + (System.currentTimeMillis() - begin));

      } else {
        System.out.println("目录下无文件,跳过处理...");
      }

    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("处理异常:::" + e);
    } finally {
      DBUtils.closeConnection(con);
    }
  }