⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expirationlist.java

📁 jxme的一些相关程序,主要是手机上程序开发以及手机和计算机通信的一些程序资料,程序编译需要Ant支持
💻 JAVA
字号:
package net.jxta.test.cm;


import java.io.*;
import java.util.*;

public class ExpirationList {

    Hashtable table = new Hashtable ();

    static final int SCHEDULE = 1;
    static final int CANCEL   = 2;

    class Entry {
	File file;
	long timeInMyCache;
	long timeForOthers;

	Entry (File file, long timeInMyCache, long timeForOthers) {
	    this.file = file;
	    this.timeInMyCache = timeInMyCache;
	    this.timeForOthers = timeForOthers;
	}

	public String toString () {
	    return "" + file + " " + timeInMyCache + " " + timeForOthers;
	}
    }

    public static void main (String[] argv) throws Exception {
	if (argv.length != 1) {
	    System.out.println
		("Usage: java net.jxta.test.cm.ExpirationList db_file");
	} else {
	    File db = new File (argv[0]);
	    
	    ExpirationList test = new ExpirationList ();

	    test.readList (db);

	    test.printList ();
	}
    }

    void readList (File f) throws IOException {
	
	DataInputStream in = null;

	try {
	    in = new DataInputStream (new FileInputStream (f));
	    
	    readList (in);
	} catch (EOFException e) {
	    // ugh
	} finally {
	    if (in != null) {
		in.close ();
	    }
	}

    }


    void readList (DataInputStream in) throws IOException {

	int    action;
	File   file;
	long   timeInMyCache;
	long   timeoutForOthers;
	int    i = 0;

	while (true) {

	    action = in.readInt ();
	    file   = new File (in.readUTF ());
	    timeInMyCache = in.readLong ();
	    timeoutForOthers = in.readLong ();

	    if (file.exists ()) {

		switch (action) {
		case SCHEDULE:
		    if (timeInMyCache > System.currentTimeMillis ())
			table.put (file,
				   new Entry (file, 
					      timeInMyCache, 
					      timeoutForOthers));
		    break;
		case CANCEL:
		    table.remove (file);
		    break;
		}
	    }
	    
	}

    }

    public void printList () {
	Enumeration elements = table.elements ();
	Entry       entry;
	
	while (elements.hasMoreElements ()) {
	    entry = (Entry) elements.nextElement ();

	    System.out.println (entry);
	}
    }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -