Esempio n. 1
0
  private void forward(
      BufferedReader sReader,
      BufferedWriter sIdxWriter,
      AccountIndexMapper mapper,
      String fieldSplit) {
    try {
      String session = null;
      StringBuilder bd = new StringBuilder();
      while ((session = sReader.readLine()) != null) {
        String[] aIds = DataFormats.sessionStringToAccountIds(session);

        int firstIndex = mapper.putIndex(aIds[0]);
        if (aIds.length == 1) {
          bd.append(firstIndex).append(fieldSplit).append(1).append(fieldSplit).append(firstIndex);
        } else if (aIds.length > 1) {
          bd.append(firstIndex).append(fieldSplit).append(aIds.length - 1);
          for (int i = 1; i < aIds.length; i++) {
            bd.append(fieldSplit).append(mapper.putIndex(aIds[i]));
          }
        }
        bd.append("\n");
        sIdxWriter.write(bd.toString());
        bd.delete(0, bd.length());
      }
      sReader.close();
    } catch (IOException ex) {
      throw new IllegalStateException("合并MiddleFile文件错误:" + ex.getMessage());
    }
  }
Esempio n. 2
0
  private boolean initVPDatabase(
      VPDatabase vpDb, String initialVpToAcont, AccountIndexMapper mapper, String split) {
    try {
      BufferedReader vpToAcontIdxReader = FileUtil.getBufferedReader(initialVpToAcont);

      String vpToAcontIdx = null;
      StringBuilder bd = new StringBuilder(20);

      vpDb.beforeInitVP();
      while ((vpToAcontIdx = vpToAcontIdxReader.readLine()) != null) {
        if (vpToAcontIdx.length() > 2) {
          String[] fields = vpToAcontIdx.split(split);
          Preconditions.checkState(fields.length == 2, "输入文件格式错误");

          int index = Integer.valueOf(fields[1]);
          if (index <= mapper.maxIndex) {
            String acontUniId = mapper.getAccountString(Integer.valueOf(fields[1]));
            Preconditions.checkState(acontUniId != null, "未找到Index对应的Account UniqueId");

            bd.append(fields[0]).append(split).append(acontUniId);
            if (!vpDb.addInitVP(bd.toString(), split)) {
              Logger.getLogger(this.getClass().getName()).info("!!!初始化虚拟人数据库失败");
              return false;
            }
            bd.delete(0, bd.length());
          }
        }
      }
      vpDb.afterInitVP();

    } catch (IOException ex) {
      throw new IllegalStateException("初始化VPDb失败:" + ex.getMessage());
    }
    return true;
  }