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

📄 cachedjarspackagemanager.java

📁 无线通信的主要编程软件,是无线通信工作人员的必备工具,关天相关教程我会在后续传上.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                zipPackages = getZipPackages(jarin);                if (caching)                    writeCacheFile(entry, jarcanon, zipPackages, brandNew);            }            addPackages(zipPackages, jarcanon);        } catch (IOException ioe) {            // silently skip any bad directories            warning("skipping bad jar, '" +                    (jarfile != null ?                          jarfile.toString() :                          jarurl.toString()) +                    "'");        }    }    private void addPackages(Hashtable zipPackages, String jarfile) {        for (Enumeration e = zipPackages.keys() ; e.hasMoreElements() ;) {            String pkg = (String)e.nextElement();            String classes = (String)zipPackages.get(pkg);            int idx = classes.indexOf('@');            if (idx >= 0 && Options.respectJavaAccessibility) {                classes = classes.substring(0, idx);            }            makeJavaPackage(pkg, classes, jarfile);        }    }    // Read in cache file storing package info for a single .jar    // Return null and delete this cachefile if it is invalid    private Hashtable readCacheFile(JarXEntry entry,String jarcanon)    {        String cachefile = entry.cachefile;        long mtime = entry.mtime;        debug("reading cache, '"+jarcanon+"'");        try {            DataInputStream istream = inOpenCacheFile(cachefile);            String old_jarcanon = istream.readUTF();            long old_mtime = istream.readLong();            if ((!old_jarcanon.equals(jarcanon)) ||            (old_mtime != mtime))            {                comment("invalid cache file: "+                cachefile+", "+jarcanon+":"+                old_jarcanon+", "+mtime+":"+old_mtime);                deleteCacheFile(cachefile);                return null;            }            Hashtable packs = new Hashtable();            try {                while (true) {                    String packageName = istream.readUTF();                    String classes = istream.readUTF();                    packs.put(packageName, classes);                }            } catch (EOFException eof) {                ;            }            istream.close();            return packs;        } catch (IOException ioe) {            // if (cachefile.exists()) cachefile.delete();            return null;        }    }    // Write a cache file storing package info for a single .jar    private void writeCacheFile(JarXEntry entry,String jarcanon,    Hashtable zipPackages,boolean brandNew)    {        try {            DataOutputStream ostream = outCreateCacheFile(entry, brandNew);            ostream.writeUTF(jarcanon);            ostream.writeLong(entry.mtime);            comment("rewriting cachefile for '"+jarcanon+"'");            for (Enumeration e = zipPackages.keys() ; e.hasMoreElements() ;) {                String packageName = (String)e.nextElement();                String classes = (String)zipPackages.get(packageName);                ostream.writeUTF(packageName);                ostream.writeUTF(classes);            }            ostream.close();        } catch (IOException ioe) {            warning("can't write cache file for '"+jarcanon+"'");        }    }    /** Initializes cache. Eventually reads back cache index.     * Index persistent storage is accessed through inOpenIndex().     */    protected void initCache() {        indexModified = false;        jarfiles = new Hashtable();        try {            DataInputStream istream = inOpenIndex();            if (istream == null) return;            try {                while (true) {                    String jarcanon = istream.readUTF();                    String cachefile = istream.readUTF();                    long mtime = istream.readLong();                    jarfiles.put(jarcanon, new JarXEntry(cachefile,mtime));                }            } catch (EOFException eof) {                ;            }            istream.close();        } catch (IOException ioe) {            warning("invalid index file");        }    }    /** Write back cache index.     * Index persistent storage is accessed through outOpenIndex().     */    public void saveCache() {        if(jarfiles == null || !indexModified ) return;        indexModified = false;        comment("writing modified index file");        try {            DataOutputStream ostream = outOpenIndex();            for (Enumeration e = jarfiles.keys(); e.hasMoreElements();) {                String jarcanon = (String)e.nextElement();                JarXEntry entry = (JarXEntry)jarfiles.get(jarcanon);                ostream.writeUTF(jarcanon);                ostream.writeUTF(entry.cachefile);                ostream.writeLong(entry.mtime);            }            ostream.close();        } catch (IOException ioe) {            warning("can't write index file");        }    }    // hooks for changing cache storage    /** To pass a cachefile id by ref. And for internal use.     * See outCreateCacheFile     */    public static class JarXEntry extends Object {        /** cachefile id */        public String cachefile;        public long mtime;        public JarXEntry(String cachefile) {            this.cachefile = cachefile;        }        public JarXEntry(String cachefile,long mtime) {            this.cachefile = cachefile;            this.mtime = mtime;        }    }    /** Open cache index for reading from persistent storage - hook.     * Must Return null if this is absent.     * This default impl is part of the off-the-shelf local     * file-system cache impl.     * Can be overriden.     */    protected DataInputStream inOpenIndex() throws IOException {        File indexFile = new File(cachedir, "packages.idx");        if (!indexFile.exists()) return null;        DataInputStream istream = new DataInputStream(        new BufferedInputStream(new FileInputStream(indexFile)));        return istream;    }    /** Open cache index for writing back to persistent storage - hook.     * This default impl is part of the off-the-shelf local     * file-system cache impl.     * Can be overriden.     */    protected DataOutputStream outOpenIndex() throws IOException {        File indexFile = new File(cachedir, "packages.idx");        return new DataOutputStream(        new BufferedOutputStream(new FileOutputStream(indexFile)));    }    /** Open cache file for reading from persistent storage - hook.     * This default impl is part of the off-the-shelf local     * file-system cache impl.     * Can be overriden.     */    protected DataInputStream inOpenCacheFile(String cachefile)        throws IOException    {        return new DataInputStream(               new BufferedInputStream(               new FileInputStream(cachefile)));    }    /** Delete (invalidated) cache file from persistent storage - hook.     * This default impl is part of the off-the-shelf local     * file-system cache impl.     * Can be overriden.     */    protected void deleteCacheFile(String cachefile) {        new File(cachefile).delete();    }    /**     * Create/open cache file for rewriting back to persistent storage - hook.     * If create is false, cache file is supposed to exist and must be opened     * for rewriting, entry.cachefile is a valid cachefile id.     * If create is true, cache file must be created. entry.cachefile is a     * flat jarname to be used to produce a valid cachefile id (to be put     * back in entry.cachefile on exit).     * This default impl is part of the off-the-shelf local file-system     * cache impl.     * Can be overriden.     */    protected DataOutputStream outCreateCacheFile(JarXEntry entry,                                                  boolean create)        throws IOException    {        File cachefile = null;        if(create) {            int index = 1;            String suffix = "";            String jarname = entry.cachefile;            while (true) {                cachefile = new File(cachedir, jarname+suffix+".pkc");                //System.err.println("try cachefile: "+cachefile);                if (!cachefile.exists()) break;                suffix = "$"+index;                index += 1;            }            entry.cachefile = cachefile.getCanonicalPath();        } else cachefile = new File(entry.cachefile);        return new DataOutputStream(               new BufferedOutputStream(               new FileOutputStream(cachefile)));    }    // for default cache (local fs based) impl    private File cachedir;    /** Initialize off-the-shelf (default) local file-system cache impl.     * Must be called before {@link #initCache}.     * cachedir is the cache repository directory, this is eventually created.     * Returns true if dir works.     */    protected boolean useCacheDir(File cachedir) {        if(cachedir == null) return false;        if (!cachedir.isDirectory() && cachedir.mkdirs() == false) {            warning("can't create package cache dir, '"+cachedir+"'");            return false;        }        this.cachedir = cachedir;        return true;    }}

⌨️ 快捷键说明

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