Exemplo n.º 1
0
  public static Mapx getSiteInfo(String file) throws Exception {
    FileInputStream fin = null;
    try {
      fin = new FileInputStream(file);
      fin.read();
      byte[] bs = new byte[8];
      fin.read(bs);

      bs = new byte[4];
      if (!bufferRead(bs, fin)) {
        return null;
      }
      int len = NumberUtil.toInt(bs);
      byte[] bs = new byte[len];
      if (!bufferRead(bs, fin)) return null;
      int len;
      byte[] bs = new byte[4];
      if (!bufferRead(bs, fin)) {
        return null;
      }
      int len = NumberUtil.toInt(bs);
      byte[] bs = new byte[len];
      if (!bufferRead(bs, fin)) return null;
      int len;
      byte[] bs = ZipUtil.unzip(bs);
      DataTable dt = (DataTable) FileUtil.unserialize(bs);
      return dt.getDataRow(0).toCaseIgnoreMapx();
    } finally {
      if (fin != null)
        try {
          fin.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
    }
  }
Exemplo n.º 2
0
  public boolean importSite(String poolName) {
    User.UserData user = new User.UserData();
    user.setUserName("admin");
    user.setBranchInnerCode("86");
    user.setLogin(true);
    user.setManager(true);
    User.setCurrent(user);

    this.isNewSite =
        (("0".equals(this.map.getString("ID"))) || (StringUtil.isEmpty(this.map.getString("ID"))));
    this.NoRelas = SiteTableRela.getNoRelaArray();
    this.TableRelas = SiteTableRela.getRelas();
    this.da = new DataAccess();
    FileInputStream fin = null;
    try {
      fin = new FileInputStream(this.file);
      this.da.setAutoCommit(false);
      this.ExportCharset = ((fin.read() == 1) ? "GBK" : "UTF-8");
      byte[] bs = new byte[8];
      fin.read(bs);
      this.siteID = NumberUtil.toLong(bs);
      boolean flag = true;
      int i = 0;
      while (true) {
        bs = new byte[4];
        if (!bufferRead(bs, fin)) {
          break;
        }
        int len = NumberUtil.toInt(bs);
        bs = new byte[len];
        if (!bufferRead(bs, fin)) {
          flag = false;
          break;
        }
        Object obj = FileUtil.unserialize(bs);

        bs = new byte[4];
        if (!bufferRead(bs, fin)) {
          flag = false;
          break;
        }
        len = NumberUtil.toInt(bs);
        bs = new byte[len];
        if (!bufferRead(bs, fin)) {
          flag = false;
          break;
        }
        bs = ZipUtil.unzip(bs);
        this.task.setPercent(i * 100 / 200);
        dealOneEntry(bs, obj);
        ++i;
      }
      if (flag) {
        this.da.commit();
      } else {
        LogUtil.error("读取站点导出文件时发生错误!");
        this.da.rollback();
      }
      this.da.setAutoCommit(true);
      Site.updatePrivAndFile(this.map.getString("Alias"));
      return flag;
    } catch (Exception e1) {
      e1.printStackTrace();
      try {
        this.da.rollback();
      } catch (SQLException e) {
        e.printStackTrace();
      }
      return false;
    } finally {
      try {
        this.da.setAutoCommit(true);
      } catch (Exception e) {
        e.printStackTrace();
      }
      try {
        this.da.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
      try {
        fin.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }