Package de.desy.tine.csvUtils

Examples of de.desy.tine.csvUtils.csv


      if (myip != null) return myip;
      // try file
      csvColumn[] ipCols = new csvColumn[1];
      String[] ipa = new String[1];
      ipCols[0] = new csvColumn("ADDRESS","",new IpNameHndlr(ipa));
      csv myipFile = new csv(getCfgResource(myipFileLocation));
      int rc = myipFile.readFile(ipCols);
      myipFile.close();
      if (rc == 0 && ipa[0] != null)
      { // file found !
        TFecLog.log("fix local ip address to "+ipa[0]+" from file");
        MsgLog.log("TInitializer","fix local ip address to "+ipa[0]+" from file",0,null,1);
        return myip = ipa[0];     
View Full Code Here


        // first try csv
        csvColumn[] addrCols = new csvColumn[1];
        addrHndlr hdlr = new addrHndlr();
        addrCols[0] = new csvColumn("ADDRESS", "", hdlr);
        int rc;
        csv mcastMaskFile = new csv(getCfgResource(getFecHome() +File.separator+ "gcastmask.csv"));
        rc = mcastMaskFile.readFile(addrCols);
        mcastMaskFile.close();
        if (rc != 0)
        {
          mcastMaskFile = new csv(getCfgResource(getTineHome()+File.separator+"gcastmask.csv"));
          rc = mcastMaskFile.readFile(addrCols);
          mcastMaskFile.close();
        }
        if (rc == 0)
        {
          GCAST = hdlr.getStrValue();
          TFecLog.log("set globals multicast address from config file to " + MCAST);
View Full Code Here

        // first try csv file
        csvColumn[] addrCols = new csvColumn[1];
        addrHndlr hdlr = new addrHndlr();
        addrCols[0] = new csvColumn("ADDRESS", "", hdlr);
        int rc;
        csv mcastMaskFile = new csv(getCfgResource(getFecHome()+File.separator+"mcastmask.csv"));
        rc = mcastMaskFile.readFile(addrCols);
        mcastMaskFile.close();
        if (rc != 0)
        {
          mcastMaskFile = new csv(getCfgResource(getTineHome()+File.separator+"mcastmask.csv"));
          rc = mcastMaskFile.readFile(addrCols);
          mcastMaskFile.close();
        }
        if (rc == 0)
        {
          MCAST = hdlr.getStrValue();
          TFecLog.log("set server multicast address from config file to " + MCAST);
View Full Code Here

    stCols[9] = new csvColumn("WAIT","",new TQuery().new tmrHndlr(stRows));
    stCols[10] = new csvColumn("ACCESS","",new TQuery().new accHndlr(stRows));
    stCols[11] = new csvColumn("TOLERANCE","",new TQuery().new tolHndlr(stRows));
    stCols[12] = new csvColumn("REQUIRED","",new TQuery().new reqHndlr(stRows));
    // open it   
    csv expFile = new csv(stString.toCharArray());
    // read it
    rc = expFile.readFile(stCols,stRows);
    // close it
    if (rc != TErrorList.no_such_file)
      TFecLog.log("get registered exports and properties from exports.csv : " + TErrorList.errorString[rc]);
   
    return stRows.lst.toArray(new SelfTestItem[0]);
View Full Code Here

    setAddrFileLocation();
  }
  private static boolean isInSrvFile(SrvAddr srv)
  {
    boolean hasEntry = false;
    csv csvf = new csv(srvCacheFile);
    try
    {
      String s, hdr;
      int srv_col = -1,eqn_col = -1 ,fec_col = -1,ctx_col = -1;
      boolean done = false;
      while((s=csvf.readLine()) != null)
      {
        if (s.length() == 0) continue;
        if (s.startsWith("#") || s.startsWith(";") || s.startsWith("%")) continue;
        if (!done)
        {
          hdr = s;
          if ((srv_col=csvf.findcol(hdr,"NAME")) < 0) throw new NoSuchFieldException();
          if ((eqn_col=csvf.findcol(hdr,"EQPMODULE")) < 0) throw new NoSuchFieldException();
          if ((fec_col=csvf.findcol(hdr,"FECNAME")) < 0) throw new NoSuchFieldException();
          if ((ctx_col=csvf.findcol(hdr,"CONTEXT")) < 0) throw new NoSuchFieldException();
          done = true;
          continue;
        }
        if (csvf.namcmp(srv.expName,s,srv_col) != 0) continue;
        if (csvf.namcmp(srv.eqmName,s,eqn_col) != 0) continue;
        if (csvf.namcmp(srv.fecName,s,fec_col) != 0) continue;
        if (csvf.namcmp(srv.eqmContext,s,ctx_col) != 0) continue;
        hasEntry = true;
        break;
      }
    }
    catch (Exception e)
    { // database corrupt or not found
      MsgLog.log("TSrvEntry.isInSrvFile", e.getMessage(),TErrorList.database_not_loaded,e,1);
      hasEntry = false;
    }
    finally
    {
      csvf.close();
    }
    return hasEntry;
  }
View Full Code Here

    return hasEntry;
  }
  private static boolean isInFecFile(SrvAddr srv)
  {
    boolean hasEntry = false;
    csv csvf = new csv(fecCacheFile);
    try
    {
      String s, hdr;
      int fec_col = -1,ip_col = -1 ,port_col = -1,prot_col = -1;
      boolean done = false;
      while((s=csvf.readLine()) != null)
      {
        if (s.length() == 0) continue;
        if (s.startsWith("#") || s.startsWith(";") || s.startsWith("%")) continue;
        if (!done)
        {
          hdr = s;
          if ((fec_col=csvf.findcol(hdr,"FEC_NAME")) < 0) throw new NoSuchFieldException();
          if ((ip_col=csvf.findcol(hdr,"IP_ADDR")) < 0) throw new NoSuchFieldException();
          if ((port_col=csvf.findcol(hdr,"PORT_OFFSET")) < 0) throw new NoSuchFieldException();
          prot_col = csvf.findcol(hdr,"TINE_PROTOCOL");
          done = true;
          continue;
        }
        if (csvf.namcmp(srv.fecName,s,fec_col) != 0) continue;
        if (csvf.namcmp(srv.ipAddr,s,ip_col) != 0) continue;
        try
        {
          if (srv.portOffset != Integer.parseInt(csvf.colptr(port_col,s))) continue;
          if (prot_col < 0) continue;
          if (srv.tineProtocol != Integer.parseInt(csvf.colptr(prot_col,s))) continue;
        }
        catch (Exception e)
        {
          continue;
        }
        hasEntry = true;
        break;
      }
    }
    catch (Exception e)
    { // database corrupt or not found
      MsgLog.log("TSrvEntry.isInFecFile", e.getMessage(),TErrorList.database_not_loaded,e,1);
      hasEntry = false;
    }
    finally
    {
      csvf.close();
    }
    return hasEntry;
  }
View Full Code Here

  }
  private static boolean addToSrvFile(SrvAddr srv)
  {
    boolean hasEntry = false;
    boolean needHeader = true;
    csv csvr = new csv(srvCacheFile);
    try
    {
      File csvw = new File(cacheFilePath);
      csvw.mkdirs();
      csvw = new File(srvCacheFile + ".tmp");
      if (csvw.exists() && csvw.lastModified() > System.currentTimeMillis() - 300000)
      { // file more recent than the last 5 minutes -> some other client app is updating ?
        return false;
      }
      srvCacheW = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(srvCacheFile + ".tmp")));
      String s, hdr;
      int srv_col = -1,ctx_col = -1;
      boolean done = false;
      while((s=csvr.readLine()) != null)
      {
        if (s.length() == 0) continue;
        if (s.startsWith("#") || s.startsWith(";") || s.startsWith("%")) continue;
        if (!done)
        {
          hdr = s;
          if ((srv_col=csvr.findcol(hdr,"NAME")) < 0) throw new NoSuchFieldException();
          if ((ctx_col=csvr.findcol(hdr,"CONTEXT")) < 0) throw new NoSuchFieldException();
          srvCacheW.write(srvHdr.trim() + crlf);
          needHeader = false;
          done = true;
          continue;
        }
        if (csvr.namcmp(srv.expName,s,srv_col) == 0 &&
            csvr.namcmp(srv.eqmContext,s,ctx_col) == 0)
        { // found the entry -> update the particulars
          s = srv.expName.trim() + ", " + srv.fecName.trim() + ", " + srv.eqmName.trim()
              + ", " +  srv.eqmContext.trim() + ", " + srv.subSystem.trim();
          hasEntry = true;
        }
        srvCacheW.write(s + crlf);
      }
      if (needHeader) srvCacheW.write(srvHdr.trim() + crlf);
      if (!hasEntry)
      { // it's a new one !
        s = srv.expName.trim() + "," + srv.fecName.trim() + "," + srv.eqmName.trim()
            + "," +  srv.eqmContext.trim() + "," + srv.subSystem.trim();
        srvCacheW.write(s + crlf);       
      }
      srvCacheW.close();
      csvr.close();
      csvw = new File(srvCacheFile);
      csvw.delete();
      File srvf = new File(srvCacheFile + ".tmp");
      srvf.renameTo(new File(srvCacheFile));
    }
    catch (Exception e)
    { // database corrupt or not found
      MsgLog.log("TSrvEntry.addToSrvFile", e.getMessage(),TErrorList.database_not_loaded,e,1);
      hasEntry = false;
    }
    finally
    {
      csvr.close();
    }
    return hasEntry;
  }
View Full Code Here

  }
  private static boolean addToFecFile(SrvAddr srv)
  {
    boolean needHeader = true;
    boolean hasEntry = false;
    csv csvr = new csv(fecCacheFile);
    try
    {
      File csvw = new File(cacheFilePath);
      csvw.mkdirs();
      csvw = new File(fecCacheFile + ".tmp");
      if (csvw.exists() && csvw.lastModified() > System.currentTimeMillis() - 300000)
      { // file more recent than the last 5 minutes -> some other client app is updating ?
        return false;
      }
      fecCacheW = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fecCacheFile + ".tmp")));
      String s, hdr;
      int fec_col = -1;
      boolean done = false;
      while((s=csvr.readLine()) != null)
      {
        if (s.length() == 0) continue;
        if (s.startsWith("#") || s.startsWith(";") || s.startsWith("%")) continue;
        if (!done)
        {
          hdr = s;
          if ((fec_col=csvr.findcol(hdr,"FEC_NAME")) < 0) throw new NoSuchFieldException();
          fecCacheW.write(fecHdr.trim() + crlf);
          done = true;
          needHeader = false;
          continue;
        }
        if (csvr.namcmp(srv.fecName,s,fec_col) == 0)
        {
          s = srv.fecName.trim() + ",00000000,000000000000," + srv.ipAddr.trim() + "," +
              srv.portOffset + "," + srv.tineProtocol; 
          hasEntry = true;
        }
        fecCacheW.write(s + crlf);
      }
      if (needHeader) fecCacheW.write(fecHdr.trim() + crlf);
      if (!hasEntry)
      { // it's a new one !
        s = srv.fecName.trim() + ",00000000,000000000000," + srv.ipAddr.trim() + "," +
            srv.portOffset + "," + srv.tineProtocol; 
        fecCacheW.write(s + crlf);       
      }
      csvr.close();
      fecCacheW.close();
      csvw = new File(fecCacheFile);
      csvw.delete();
      File fecf = new File(fecCacheFile + ".tmp");
      fecf.renameTo(new File(fecCacheFile));
    }
    catch (Exception e)
    { // database corrupt or not found
      MsgLog.log("TSrvEntry.addToFecFile", e.getMessage(),TErrorList.database_not_loaded,e,1);
      hasEntry = false;
    }
    finally
    {
      csvr.close();
    }
    return hasEntry;
  }
View Full Code Here

  {
    boolean needHeader = true;
    boolean hasEntry = false;
    String tfn = filename+".tmp";
    String gfn = filename+".csv";
    csv csvr = new csv(gfn);
    BufferedWriter grpCacheW;
    try
    {
      File csvw = new File(tfn);
      if (csvw.exists() && csvw.lastModified() > System.currentTimeMillis() - 600000)
      { // file more recent than the last 5 minutes -> some other client app is updating ?
        return false;
      }
      csvw = new File(tfn.substring(0, tfn.lastIndexOf(File.separatorChar)));
      csvw.mkdirs();
      grpCacheW = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tfn)));
      String s, hdr;
      int col = -1;
      boolean done = false;
      while((s=csvr.readLine()) != null)
      {
        if (s.length() == 0) continue;
        if (s.startsWith("#") || s.startsWith(";") || s.startsWith("%")) continue;
        if (!done)
        {
          hdr = s;
          if ((col=csvr.findcol(hdr,column)) < 0) throw new NoSuchFieldException();
          grpCacheW.write(column + crlf);
          done = true;
          needHeader = false;
          continue;
        }
        if (csvr.namcmp(tgt,s,col) == 0) hasEntry = true;
        grpCacheW.write(s + crlf);
      }
      if (needHeader) grpCacheW.write(column + crlf);
      if (!hasEntry)
      { // it's a new one !
        grpCacheW.write(tgt + crlf);       
      }
      grpCacheW.close();
      if (hasEntry)
      { // remove the .tmp file
        new File(tfn).delete();
      }
      else
      { // do the shuffle ...
        csvr.close();
        new File(gfn).delete();
        File tf = new File(tfn);
        tf.renameTo(new File(gfn));
      }
    }
    catch (Exception e)
    { // database corrupt or not found
      MsgLog.log("TSrvEntry.addToGroupCacheFile", e.getMessage(),TErrorList.database_not_loaded,e,1);
      hasEntry = false;
    }
    finally
    {
      csvr.close();
    }
    return hasEntry;
  }
View Full Code Here

        resolutionHistory += "address found in local cache\n";
        return 0;
      }
    }
    // try the dynamic cache
    srvFile = new csv(srvCacheFile);
    dbFilePath = cacheFilePath;
    int cc = fillinAddressFromFileCache(devName,srvName,ctxName);
    if (cc != 0)
    { // not found, try the static cache
      srvFile = new csv(srvR);
      dbFilePath = tineHomePath;
      cc = fillinAddressFromFileCache(devName,srvName,ctxName);
    }
    return cc;
  }
View Full Code Here

TOP

Related Classes of de.desy.tine.csvUtils.csv

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.