示例#1
1
文件: Traffic.java 项目: fin-nick/fj
  // Loads traffic from file
  public final void load() {
    sessionInTraffic = 0;
    sessionOutTraffic = 0;
    savedCost = 0;
    lastTimeUsed = new Date(1);
    costPerDaySum = 0;
    savedSince = new Date();
    Storage traffic = new Storage("traffic");
    try {
      traffic.open(false);

      byte[] buf = traffic.getRecord(2);
      ByteArrayInputStream bais = new ByteArrayInputStream(buf);
      DataInputStream dis = new DataInputStream(bais);

      allInTraffic = dis.readInt();
      allOutTraffic = dis.readInt();
      savedSince.setTime(dis.readLong());
      lastTimeUsed.setTime(dis.readLong());
      savedCost = dis.readInt();
    } catch (Exception e) {
      savedSince.setTime(new Date().getTime());
      allInTraffic = 0;
      sessionOutTraffic = 0;
      savedCost = 0;
    }
    traffic.close();
  }
示例#2
0
  /**
   * creates a clone of this object, the EventId field is not cloned.
   *
   * @return EventData object
   */
  public Object clone() {
    EventData myClone = new EventData();

    myClone.mType = mType;

    myClone.mStatus = mStatus;

    myClone.mCd = mCd;

    myClone.mAttempt = mAttempt;

    if (mAddDate != null) {
      myClone.mAddDate = (Date) mAddDate.clone();
    }

    myClone.mAddBy = mAddBy;

    if (mModDate != null) {
      myClone.mModDate = (Date) mModDate.clone();
    }

    myClone.mModBy = mModBy;

    myClone.mEventPriority = mEventPriority;

    if (mProcessTime != null) {
      myClone.mProcessTime = (Date) mProcessTime.clone();
    }

    return myClone;
  }
  public void messageReceived(int to, Message message) {
    Date date = Calendar.getInstance().getTime();

    if (message instanceof RadioSignalResultsMsg) {
      RadioSignalResultsMsg resultMsg = (RadioSignalResultsMsg) message;
      log(
          date
              + "\t"
              + date.getTime()
              + "\t"
              + "RADIO15.4_RESULT_MSG"
              + "\t"
              + resultMsg.get_idReceiver()
              + "\t"
              + resultMsg.get_idSender()
              + "\t"
              + resultMsg.get_seqno()
              + "\t"
              + resultMsg.get_rssi()
              + "\t"
              + resultMsg.get_lqi()
              + "\t"
              + resultMsg.get_timestamp());
    } else {
      log(date + "\t" + date.getTime() + "\t UNKNOWN_MSG" + "\t" + message.toString());
    }
  }
示例#4
0
  // Returns present local date time hours minutes and seconds
  public String getDate() {
    // Instantiate a Date object
    Date date = new Date();

    // display time and date using toString()
    return (date.toString());
  }
示例#5
0
    @Override
    public void run() {
      synchronized (RESTReservations.this) {
        Iterator<Conference> conferenceIterator = conferenceMap.values().iterator();

        while (conferenceIterator.hasNext()) {
          Conference conference = conferenceIterator.next();
          Date startTimeDate = conference.getStartTime();
          if (startTimeDate == null) {
            logger.error("No 'start_time' for conference: " + conference.getName());
            continue;
          }
          long startTime = startTimeDate.getTime();
          long duration = conference.getDuration();
          // Convert duration to millis
          duration = duration * 1000L;
          long now = System.currentTimeMillis();
          if (now - startTime > duration - EXPIRE_INTERVAL) {
            // Destroy the conference
            String mucRoomName = conference.getMucRoomName();

            deleteConference(conference.getId());

            conferenceIterator.remove();

            focusManager.destroyConference(mucRoomName, "Scheduled conference duration exceeded.");
          }
        }
      }
    }
示例#6
0
  /**
   * Constructor
   *
   * @param name name of bot
   * @param path root path of Program AB
   * @param action Program AB action
   */
  public Bot(String name, String path, String action) {
    int cnt = 0;
    int elementCnt = 0;
    this.name = name;
    setAllPaths(path, name);
    this.brain = new Graphmaster(this);

    this.learnfGraph = new Graphmaster(this, "learnf");
    this.learnGraph = new Graphmaster(this, "learn");
    //      this.unfinishedGraph = new Graphmaster(this);
    //  this.categories = new ArrayList<Category>();

    preProcessor = new PreProcessor(this);
    addProperties();
    cnt = addAIMLSets();
    if (MagicBooleans.trace_mode) System.out.println("Loaded " + cnt + " set elements.");
    cnt = addAIMLMaps();
    if (MagicBooleans.trace_mode) System.out.println("Loaded " + cnt + " map elements");
    this.pronounSet = getPronouns();
    AIMLSet number = new AIMLSet(MagicStrings.natural_number_set_name, this);
    setMap.put(MagicStrings.natural_number_set_name, number);
    AIMLMap successor = new AIMLMap(MagicStrings.map_successor, this);
    mapMap.put(MagicStrings.map_successor, successor);
    AIMLMap predecessor = new AIMLMap(MagicStrings.map_predecessor, this);
    mapMap.put(MagicStrings.map_predecessor, predecessor);
    AIMLMap singular = new AIMLMap(MagicStrings.map_singular, this);
    mapMap.put(MagicStrings.map_singular, singular);
    AIMLMap plural = new AIMLMap(MagicStrings.map_plural, this);
    mapMap.put(MagicStrings.map_plural, plural);
    // System.out.println("setMap = "+setMap);
    Date aimlDate = new Date(new File(aiml_path).lastModified());
    Date aimlIFDate = new Date(new File(aimlif_path).lastModified());
    if (MagicBooleans.trace_mode)
      System.out.println("AIML modified " + aimlDate + " AIMLIF modified " + aimlIFDate);
    // readUnfinishedIFCategories();
    MagicStrings.pannous_api_key = Utilities.getPannousAPIKey(this);
    MagicStrings.pannous_login = Utilities.getPannousLogin(this);
    if (action.equals("aiml2csv")) addCategoriesFromAIML();
    else if (action.equals("csv2aiml")) addCategoriesFromAIMLIF();
    else if (action.equals("chat-app")) {
      if (MagicBooleans.trace_mode) System.out.println("Loading only AIMLIF files");
      cnt = addCategoriesFromAIMLIF();
    } else if (aimlDate.after(aimlIFDate)) {
      if (MagicBooleans.trace_mode) System.out.println("AIML modified after AIMLIF");
      cnt = addCategoriesFromAIML();
      writeAIMLIFFiles();
    } else {
      addCategoriesFromAIMLIF();
      if (brain.getCategories().size() == 0) {
        System.out.println("No AIMLIF Files found.  Looking for AIML");
        cnt = addCategoriesFromAIML();
      }
    }
    Category b =
        new Category(
            0, "PROGRAM VERSION", "*", "*", MagicStrings.program_name_version, "update.aiml");
    brain.addCategory(b);
    brain.nodeStats();
    learnfGraph.nodeStats();
  }
示例#7
0
  public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    Date startTime = new Date();
    String fname = "p079_keylog.txt";
    FileReader fr = new FileReader(fname);
    BufferedReader br = new BufferedReader(fr);
    SortedSet<String> slines = new TreeSet<String>();
    String line = "";

    while ((line = br.readLine()) != null) {
      slines.add(line);
    }

    String start = slines.first().split("")[0];

    String ans = "";

    for (String l : slines) {
      // System.out.println(l);
      for (String l2 : slines) {
        if (l2.contains(start) && l2.indexOf(start) > 0) start = l2.split("")[0];
      }
    }
    ans += start;
    // System.out.println(ans);
    for (int i = 0; i < 10; i++) {
      start = (getNext(slines, start));
      if (start == null) break;
      ans += start;
      // System.out.println(ans);
    }
    Date endTime = new Date();
    System.out.println(ans + " in " + (endTime.getTime() - startTime.getTime()) + " ms.");
  }
示例#8
0
  public void get() throws Exception {
    byte[] b = new byte[8192];
    int n = 0, t = 0; // t == total amount of downloaded bytes
    long length = smbFile.length(), initialTime, currentTime;
    float percentage;

    out = new FileOutputStream(downloadDir + "/" + smbFile.getName());

    Date date = new Date();
    initialTime = date.getTime();

    while ((n = in.read(b)) > 0) {
      t += n;
      percentage = ((float) t / (float) length) * 100;
      currentTime = new Date().getTime();

      float iets = (float) t;
      float tijd = (float) ((currentTime - initialTime) + 1);
      float speed = iets / tijd;

      System.out.printf("%3.2f   %f KB/s\r", percentage, speed);
      System.out.flush();
      out.write(b);
    }

    out.close();
    System.out.println();
  }
示例#9
0
  private void ConnectKnowledgeBaseBtnMouseClicked(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_ConnectKnowledgeBaseBtnMouseClicked

    String sPrjFile = ProjectNameTF.getText().trim();
    String sLocationURI = sURI + "Location";

    Collection errors = new ArrayList();
    Date d1 = new Date();
    long l1 = d1.getTime();
    prj = Project.loadProjectFromFile(sPrjFile, errors);
    owlModel = (OWLModel) prj.getKnowledgeBase();

    kb = prj.getKnowledgeBase();
    URI uri = prj.getActiveRootURI();

    Collection colNumberOfInstance = kb.getInstances();
    lNumberOfInstance = colNumberOfInstance.size();

    Date d2 = new Date();
    long l2 = d2.getTime();
    lLoadedTime = (l2 - l1);

    theLogger.info("Connected to MySQL in " + lLoadedTime + " ms");
    theLogger.info("KB has " + lNumberOfInstance + " instances");

    LoggingAreaTA.append("Project has " + lNumberOfInstance + " in total\n");
    LoggingAreaTA.append("Project is loaded in " + lLoadedTime + " ms\n");
  } // GEN-LAST:event_ConnectKnowledgeBaseBtnMouseClicked
示例#10
0
  public static void main(String[] argv) {
    String hostName;
    if (argv.length == 0) hostName = "localhost";
    else hostName = argv[0];

    try {
      Socket sock = new Socket(hostName, TIME_PORT);
      ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(sock.getInputStream()));

      // Read and validate the Object
      Object o = is.readObject();
      if (o == null) {
        System.err.println("Read null from server!");
      } else if ((o instanceof Date)) {

        // Valid, so cast to Date, and print
        Date d = (Date) o;
        System.out.println("Server host is " + hostName);
        System.out.println("Time there is " + d.toString());

      } else {
        throw new IllegalArgumentException("Wanted Date, got " + o);
      }
    } catch (ClassNotFoundException e) {
      System.err.println("Wanted date, got INVALID CLASS (" + e + ")");
    } catch (IOException e) {
      System.err.println(e);
    }
  }
示例#11
0
文件: Client.java 项目: pksunkara/c3
  // function to do the join use case
  public static void share() throws Exception {
    HttpPost method = new HttpPost(url + "/share");
    String ipAddress = null;

    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
    while (en.hasMoreElements()) {
      NetworkInterface ni = (NetworkInterface) en.nextElement();
      if (ni.getName().equals("eth0")) {
        Enumeration<InetAddress> en2 = ni.getInetAddresses();
        while (en2.hasMoreElements()) {
          InetAddress ip = (InetAddress) en2.nextElement();
          if (ip instanceof Inet4Address) {
            ipAddress = ip.getHostAddress();
            break;
          }
        }
        break;
      }
    }

    method.setEntity(new StringEntity(username + ';' + ipAddress, "UTF-8"));
    try {
      ResponseHandler<String> responseHandler = new BasicResponseHandler();
      connIp = client.execute(method, responseHandler);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }

    // get present time
    date = new Date();
    long start = date.getTime();

    // Execute the vishwa share process
    Process p = Runtime.getRuntime().exec("java -jar vishwa/JVishwa.jar " + connIp);

    String ch = "alive";
    System.out.println("Type kill to unjoin from the grid");

    while (!ch.equals("kill")) {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      ch = in.readLine();
    }

    p.destroy();

    date = new Date();
    long end = date.getTime();
    long durationInt = end - start;

    String duration = String.valueOf(durationInt);
    method = new HttpPost(url + "/shareAck");
    method.setEntity(new StringEntity(username + ";" + duration, "UTF-8"));
    try {
      client.execute(method);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }
  }
示例#12
0
  /**
   * creates a clone of this object, the ProductViewDefId field is not cloned.
   *
   * @return ProductViewDefData object
   */
  public Object clone() {
    ProductViewDefData myClone = new ProductViewDefData();

    myClone.mStatusCd = mStatusCd;

    myClone.mAccountId = mAccountId;

    myClone.mAttributename = mAttributename;

    myClone.mSortOrder = mSortOrder;

    myClone.mWidth = mWidth;

    myClone.mStyleClass = mStyleClass;

    myClone.mProductViewCd = mProductViewCd;

    if (mAddDate != null) {
      myClone.mAddDate = (Date) mAddDate.clone();
    }

    myClone.mAddBy = mAddBy;

    if (mModDate != null) {
      myClone.mModDate = (Date) mModDate.clone();
    }

    myClone.mModBy = mModBy;

    return myClone;
  }
示例#13
0
 /**
  * 验证项目是否ok
  *
  * @param contextPath 项目路径
  */
 public static boolean isdomainok(String contextPath, String securityKey, String domiankey) {
   try {
     if (contextPath.indexOf("127.0.") > -1 || contextPath.indexOf("192.168.") > -1) {
       return true;
     }
     String dedomaininfo = PurseSecurityUtils.decryption(domiankey, securityKey);
     Gson gson = new Gson();
     JsonParser jsonParser = new JsonParser();
     JsonObject jsonObject = jsonParser.parse(dedomaininfo).getAsJsonObject();
     Map<String, String> map =
         gson.fromJson(jsonObject, new TypeToken<Map<String, String>>() {}.getType());
     String domain = map.get("domain");
     if (contextPath.indexOf(domain) < 0) {
       System.exit(2);
       return false;
     }
     String dt = map.get("dt");
     if (com.yizhilu.os.core.util.StringUtils.isNotEmpty(dt)) {
       Date t = DateUtils.toDate(dt, "yyyy-MM-dd");
       if (t.compareTo(new Date()) < 0) {
         System.exit(3);
         return false;
       }
     }
     return true;
   } catch (Exception e) {
     return false;
   }
 }
示例#14
0
  /**
   * creates a clone of this object, the OrderAssocId field is not cloned.
   *
   * @return OrderAssocData object
   */
  public Object clone() {
    OrderAssocData myClone = new OrderAssocData();

    myClone.mOrder1Id = mOrder1Id;

    myClone.mOrder2Id = mOrder2Id;

    myClone.mOrderAssocCd = mOrderAssocCd;

    myClone.mOrderAssocStatusCd = mOrderAssocStatusCd;

    if (mAddDate != null) {
      myClone.mAddDate = (Date) mAddDate.clone();
    }

    myClone.mAddBy = mAddBy;

    if (mModDate != null) {
      myClone.mModDate = (Date) mModDate.clone();
    }

    myClone.mModBy = mModBy;

    myClone.mWorkOrderItemId = mWorkOrderItemId;

    myClone.mServiceTicketId = mServiceTicketId;

    return myClone;
  }
  public SetIfModifiedSince() throws Exception {

    serverSock = new ServerSocket(0);
    int port = serverSock.getLocalPort();

    Thread thr = new Thread(this);
    thr.start();

    Date date = new Date(new Date().getTime() - 1440000); // this time yesterday
    URL url;
    HttpURLConnection con;

    // url = new URL(args[0]);
    url = new URL("http://localhost:" + String.valueOf(port) + "/anything");
    con = (HttpURLConnection) url.openConnection();

    con.setIfModifiedSince(date.getTime());
    con.connect();
    int ret = con.getResponseCode();

    if (ret == 304) {
      System.out.println("Success!");
    } else {
      throw new RuntimeException(
          "Test failed! Http return code using setIfModified method is:"
              + ret
              + "\nNOTE:some web servers are not implemented according to RFC, thus a failed test does not necessarily indicate a bug in setIfModifiedSince method");
    }
  }
 @Test
 public void setDeleteAt() throws IOException, DateParseException {
   expectStatusCode(202, false);
   prepareMetadata();
   final Date date = DateUtils.parseDate("Mon, 03 Sep 2001 05:40:33 GMT");
   object.setDeleteAt(date);
   verifyHeaderValue(Long.toString(date.getTime() / 1000), X_DELETE_AT, "POST");
 }
示例#17
0
 private int getRand(int min, int max) {
   Date now = new Date();
   long seed = now.getTime();
   Random randomizer = new Random(seed);
   int n = max - min + 1;
   int i = randomizer.nextInt(n);
   if (i < 0) i = -i;
   return min + i;
 }
示例#18
0
  /**
   * Validate the token expiration date.
   *
   * @param expirationDate - Token expiration date.
   * @return - Token status.
   */
  public static boolean isValid(Date expirationDate) {
    Date currentDate = new Date();
    String formattedDate = dateFormat.format(currentDate);
    currentDate = convertDate(formattedDate);

    boolean isExpired = currentDate.after(expirationDate);
    boolean isEqual = currentDate.equals(expirationDate);
    return isExpired || isEqual;
  }
示例#19
0
  public static void main(String[] args) throws Exception {
    Date date = new Date();
    inputString = new ArrayList<String>();
    ans = new ArrayList();
    ans2 = new ArrayList();
    if (args.length == 0) {
      System.err.println("[-iu] [-t THREAD_COUNT] [-o OUTPUT] [FILES...]");
      System.exit(1);
    }

    try {
      readKeys(args);
    } catch (Exception e) {
      System.err.println("Error in set keys :" + e.getMessage());
      System.exit(1);
    }

    queue = new LinkedBlockingQueue();
    service = Executors.newFixedThreadPool(numberThreads);
    Sorter sorter[] = new Sorter[numberThreads];

    try {
      reader(inputString);
    } catch (Exception e) {
      System.err.println("Error in reader");
      System.exit(1);
    }

    for (int i = 0; i < numberThreads; i++) {
      sorter[i] = new Sorter(i);
      sorter[i].start();
    }

    for (int i = 0; i < numberThreads; i++) {
      sorter[i].join();
    }

    service.shutdown();
    service.awaitTermination(1, TimeUnit.DAYS);

    Merge merge = new Merge(ans2, 0);
    merge.run();
    merge.join();

    service.shutdown();
    service.awaitTermination(1, TimeUnit.DAYS);

    try {
      printAnswer(outputFile);
    } catch (Exception e) {
      System.err.println("Error in print answer");
      System.exit(1);
    }
    Date date2 = new Date();
    System.out.println(date2.getTime() - date.getTime());
  }
示例#20
0
 /**
  * Returns the time that the file denoted by this abstract pathname was last modified.
  *
  * @return A <code>long</code> value representing the time the file was last modified, measured in
  *     system-dependent way.
  */
 public long lastModified() {
   try {
     Date date = ftpClient.lastModified(getPath());
     return date.getTime();
   } catch (IOException e) {
     return 0;
   } catch (FTPException e) {
     return 0;
   }
 }
 public static void sleep(long milliseconds) {
   Date d;
   long start, now;
   d = new Date();
   start = d.getTime();
   do {
     d = new Date();
     now = d.getTime();
   } while ((now - start) < milliseconds);
 }
示例#22
0
文件: Client.java 项目: pksunkara/c3
  // function to do the compute use case
  public static void compute() throws Exception {
    HttpPost method = new HttpPost(url + "/compute");

    method.setEntity(new StringEntity(username, "UTF-8"));

    try {
      ResponseHandler<String> responseHandler = new BasicResponseHandler();
      connIp = client.execute(method, responseHandler);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }

    System.out.println("Give the file name which has to be put in the grid for computation");

    // input of the file name to be computed
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String name = in.readLine();

    // get the absolute path of the current working directory
    File directory = new File(".");
    String pwd = directory.getAbsolutePath();

    // get present time
    date = new Date();
    long start = date.getTime();

    String cmd = "java -classpath " + pwd + "/vishwa/JVishwa.jar:. " + name + " " + connIp;
    System.out.println(cmd);

    // Execute the vishwa compute process
    Process p = Runtime.getRuntime().exec(cmd);

    // wait till the compute process is completed
    // check for the status code (0 for successful termination)
    int status = p.waitFor();

    if (status == 0) {
      System.out.println("Compute operation successful. Check the directory for results");
    }

    date = new Date();
    long end = date.getTime();
    long durationInt = end - start;

    String duration = String.valueOf(durationInt);
    method = new HttpPost(url + "/computeAck");
    method.setEntity(new StringEntity(username + ";" + duration, "UTF-8"));
    try {
      client.execute(method);
    } catch (IOException e) {
      System.err.println("Fatal transport error: " + e.getMessage());
      e.printStackTrace();
    }
  }
示例#23
0
  public static void main(String[] args) {
    Date start = new Date();
    if (args.length < 3) {
      System.out.println("Wrong number of arguments:\n" + USAGE);
      return;
    }

    // get # threads
    int tc = Integer.parseInt(args[0]);
    String outfile = args[1];

    // make a threadsafe queue of all files to process
    ConcurrentLinkedQueue<String> files = new ConcurrentLinkedQueue<String>();
    for (int i = 2; i < args.length; i++) {
      files.add(args[i]);
    }

    // hastable for results
    Hashtable<String, Integer> results = new Hashtable<String, Integer>(HASH_SIZE, LF);

    // spin up the threads
    Thread[] workers = new Thread[tc];
    for (int i = 0; i < tc; i++) {
      workers[i] = new Worker(files, results);
      workers[i].start();
    }

    // wait for them to finish
    try {
      for (int i = 0; i < tc; i++) {
        workers[i].join();
      }
    } catch (Exception e) {
      System.out.println("Caught Exception: " + e.getMessage());
    }

    // terminal output
    Date end = new Date();
    System.out.println(end.getTime() - start.getTime() + " total milliseconds");
    System.out.println(results.size() + " unique words");

    // sort results for easy comparison/verification
    List<Map.Entry<String, Integer>> sorted_results =
        new ArrayList<Map.Entry<String, Integer>>(results.entrySet());
    Collections.sort(sorted_results, new KeyComp());
    // file output
    try {
      PrintStream out = new PrintStream(outfile);
      for (int i = 0; i < sorted_results.size(); i++) {
        out.println(sorted_results.get(i).getKey() + "\t" + sorted_results.get(i).getValue());
      }
    } catch (Exception e) {
      System.out.println("Caught Exception: " + e.getMessage());
    }
  }
  public static void dumpEnvelope(Message m) throws Exception {
    pr("This is the message envelope");
    pr("---------------------------");
    Address[] a;
    // FROM
    if ((a = m.getFrom()) != null) {
      for (int j = 0; j < a.length; j++) pr("FROM: " + a[j].toString());
    }

    // TO
    if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
      for (int j = 0; j < a.length; j++) pr("TO: " + a[j].toString());
    }

    // SUBJECT
    pr("SUBJECT: " + m.getSubject());

    // DATE
    Date d = m.getSentDate();
    pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN"));

    // FLAGS
    Flags flags = m.getFlags();
    StringBuffer sb = new StringBuffer();
    Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags

    boolean first = true;
    for (int i = 0; i < sf.length; i++) {
      String s;
      Flags.Flag f = sf[i];
      if (f == Flags.Flag.ANSWERED) s = "\\Answered";
      else if (f == Flags.Flag.DELETED) s = "\\Deleted";
      else if (f == Flags.Flag.DRAFT) s = "\\Draft";
      else if (f == Flags.Flag.FLAGGED) s = "\\Flagged";
      else if (f == Flags.Flag.RECENT) s = "\\Recent";
      else if (f == Flags.Flag.SEEN) s = "\\Seen";
      else continue; // skip it
      if (first) first = false;
      else sb.append(' ');
      sb.append(s);
    }

    String[] uf = flags.getUserFlags(); // get the user flag strings
    for (int i = 0; i < uf.length; i++) {
      if (first) first = false;
      else sb.append(' ');
      sb.append(uf[i]);
    }
    pr("FLAGS: " + sb.toString());

    // X-MAILER
    String[] hdrs = m.getHeader("X-Mailer");
    if (hdrs != null) pr("X-Mailer: " + hdrs[0]);
    else pr("X-Mailer NOT available");
  }
  public void writeRecord(String stnName, Date obsDate, StructureData sdata) throws IOException {
    StationTracker stnTracker = stationMap.get(stnName);
    ProfileTracker proTracker = stnTracker.profileMap.get(obsDate);

    if (proTracker == null) {
      proTracker = new ProfileTracker(profileIndex);
      stnTracker.profileMap.put(obsDate, proTracker);

      stnTracker.link.add(profileIndex);
      stnTracker.lastChild = profileIndex;
      stnTracker.numChildren++;

      try {
        originTime[0] = profileIndex; // 2d index
        timeArray.set(0, dateFormatter.toDateTimeStringISO(obsDate));
        parentArray.set(0, stnTracker.parent_index);
        ncfile.writeStringData(timeName, originTime, timeArray);
        ncfile.write(parentStationIndex, originTime, parentArray);
      } catch (InvalidRangeException e) {
        e.printStackTrace();
        throw new IllegalStateException(e);
      }

      profileIndex++;
    }

    // needs to be wrapped as an ArrayStructure, even though we are only writing one at a time.
    ArrayStructureW sArray = new ArrayStructureW(sdata.getStructureMembers(), new int[] {1});
    sArray.setStructureData(sdata, 0);

    // track the min and max date
    if ((minDate == null) || minDate.after(obsDate)) minDate = obsDate;
    if ((maxDate == null) || maxDate.before(obsDate)) maxDate = obsDate;

    timeArray.set(0, dateFormatter.toDateTimeStringISO(obsDate));
    parentArray.set(0, proTracker.parent_index);

    proTracker.link.add(recno);
    proTracker.lastChild = recno; // not currently used
    proTracker.numChildren++;

    // write the recno record
    origin[0] = recno; // 1d index
    originTime[0] = recno; // 2d index
    try {
      ncfile.write("record", origin, sArray);
      ncfile.write(parentProfileIndex, originTime, parentArray);
    } catch (InvalidRangeException e) {
      e.printStackTrace();
      throw new IllegalStateException(e);
    }

    recno++;
  }
示例#26
0
 /**
  * Remove all files with date < cutoff.
  *
  * @param cutoff earliest date to allow
  * @param sbuff write results here, null is ok.
  */
 public static void cleanCache(Date cutoff, StringBuilder sbuff) {
   if (sbuff != null) sbuff.append("CleanCache files before ").append(cutoff).append("\n");
   File dir = new File(root);
   for (File file : dir.listFiles()) {
     Date lastMod = new Date(file.lastModified());
     if (lastMod.before(cutoff)) {
       file.delete();
       if (sbuff != null)
         sbuff.append(" delete ").append(file).append(" (").append(lastMod).append(")\n");
     }
   }
 }
示例#27
0
 public static long getDateHeader(String stringValue) throws ParseException {
   for (SimpleDateFormat dateHeaderFormat : dateHeaderFormats) {
     try {
       Date date = dateHeaderFormat.parse(stringValue);
       return date.getTime();
     } catch (
         Exception
             e) { // used to be ParseException, but NumberFormatException may be thrown as well
       // Ignore and try next
     }
   }
   throw new ParseException(stringValue, 0);
 }
示例#28
0
  void rrToWire(DataByteOutputStream out, Compression c, boolean canonical) {
    if (signature == null) return;

    out.writeShort(covered);
    out.writeByte(alg);
    out.writeByte(labels);
    out.writeInt(origttl);
    out.writeInt((int) (expire.getTime() / 1000));
    out.writeInt((int) (timeSigned.getTime() / 1000));
    out.writeShort(footprint);
    signer.toWire(out, null, canonical);
    out.writeArray(signature);
  }
示例#29
0
  /** Update Date values */
  private void updateDate() {
    int dateStamp = rmcSentence.getDate();

    if (dateStamp > 0) {
      String rd = Integer.toString(dateStamp);
      int dd = Integer.parseInt(rd.substring(0, rd.length() - 4));
      int mm = Integer.parseInt(rd.substring(rd.length() - 4, rd.length() - 2));
      int yy = Integer.parseInt(rd.substring(rd.length() - 2, rd.length()));

      date.setDay(dd);
      date.setMonth(mm);
      date.setYear(yy);
    }
  }
示例#30
0
  /** Update Time values */
  private void updateTime() {

    int timeStamp = ggaSentence.getTime();

    if (timeStamp > 0) {
      String rt = Integer.toString(timeStamp);
      int hh = Integer.parseInt(rt.substring(0, rt.length() - 4));
      int mm = Integer.parseInt(rt.substring(rt.length() - 4, rt.length() - 2));
      int ss = Integer.parseInt(rt.substring(rt.length() - 2, rt.length()));

      date.setHours(hh);
      date.setMinutes(mm);
      date.setSeconds(ss);
    }
  }