Package de.desy.tine.csvUtils

Examples of de.desy.tine.csvUtils.csv


  }
  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

  private static String dbFilePath = null;
  public String[] getGroupMembersFromFileCache(String ctxName,String srvName)
  {
    String grpCacheFile = dbFilePath+"GROUPS"+File.separator+
                   ctxName+File.separator+srvName+".csv";
    csv grpDbFile = new csv(grpCacheFile);
   
    String fn = grpDbFile.getFileName();
    if (fn == null)
      fn = TInitializerFactory.getInstance().getInitializer().getFecHome()+File.separator+"eqpdbase.csv";
    ArrayList<String> lst = new ArrayList<String>();
    try
    {
      String s, hdr;
      int mem_col = -1;
      boolean done = false;
      while((s=grpDbFile.readLine()) != null)
      {
        if (s.length() == 0) continue;
        if (s.startsWith("#") || s.startsWith(";") || s.startsWith("%")) continue;
        if (!done)
        {
          hdr = s;
          if ((mem_col=grpDbFile.findcol(hdr,"MEMBERS")) < 0) throw new NoSuchFieldException();
          done = true;
          continue;
        }
        lst.add(srvFile.colptr(mem_col,s));
      }
    }
    catch (Exception e)
    { // database corrupt or not found
      MsgLog.log("getGroupMembersFromFileCache", e.getMessage(),TErrorList.database_not_loaded,e,1);
      resolutionHistory += "getGroupMembersFromFileCache: "+e.getMessage()+"\n";
    }
    finally
    {
      grpDbFile.close();
    }
    return lst.toArray(new String[0])
  }
View Full Code Here

  boolean groupFileHasDevice(String ctxName,String memName,String tgtName)
  {
    String grpCacheFile = dbFilePath+"GROUPS"+File.separator+
                   ctxName+File.separator+memName+File.separator+
                   "devices.csv";
    csv grpDbFile = new csv(grpCacheFile);
   
    String fn = grpDbFile.getFileName();
    if (fn == null)
      fn = TInitializerFactory.getInstance().getInitializer().getFecHome()+File.separator+"eqpdbase.csv";
    boolean found = false;
    try
    {
      String s, hdr;
      int dev_col = -1;
      boolean done = false;
      while((s=grpDbFile.readLine()) != null)
      {
        if (s.length() == 0) continue;
        if (s.startsWith("#") || s.startsWith(";") || s.startsWith("%")) continue;
        if (!done)
        {
          hdr = s;
          if ((dev_col=grpDbFile.findcol(hdr,"DEVICES")) < 0) throw new NoSuchFieldException();
          done = true;
          continue;
        }
        if (grpDbFile.namcmp(tgtName,s,dev_col) == 0)
        {
          found = true;
          break;
        }
      }
    }
    catch (Exception e)
    { // database corrupt or not found
      MsgLog.log("groupFileHasDevice", e.getMessage(),TErrorList.database_not_loaded,e,1);
      resolutionHistory += "groupFileHasDevice: "+e.getMessage()+"\n";
    }
    finally
    {
      grpDbFile.close();
    }   
    return found;
  }
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.