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

📄 nntprepositoryimpl.java

📁 邮件服务器系统 支持SMTP POP3 是著名的Apache写 有一定的参考价值
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    new StringBuffer(128)                        .append("A file exists in the NNTP root directory with the same name as a newsgroup.  File ")                        .append(groupName)                        .append("in directory ")                        .append(rootPathString)                        .append(" is not a directory.");                throw new ConfigurationException(errorBuffer.toString());            }        }        if ( tempPath.exists() == false ) {            tempPath.mkdirs();        } else if (!(tempPath.isDirectory())) {            StringBuffer errorBuffer =                new StringBuffer(128)                    .append("NNTP repository temp directory is improperly configured.  The specified path ")                    .append(tempPathString)                    .append(" is not a directory.");            throw new ConfigurationException(errorBuffer.toString());        }        getLogger().debug("repository initialization done");    }    /**     * @see org.apache.james.nntpserver.repository.NNTPRepository#isReadOnly()     */    public boolean isReadOnly() {        return readOnly;    }    /**     * @see org.apache.james.nntpserver.repository.NNTPRepository#getGroup(String)     */    public NNTPGroup getGroup(String groupName) {        if (definedGroupsOnly && groupNameMap.get(groupName) == null) {            if (getLogger().isDebugEnabled()) {                getLogger().debug(groupName + " is not a newsgroup hosted on this server.");            }            return null;        }        File groupFile = new File(rootPath,groupName);        NNTPGroup groupToReturn = null;        synchronized(this) {            groupToReturn = (NNTPGroup)repositoryGroups.get(groupName);            if ((groupToReturn == null) && groupFile.exists() && groupFile.isDirectory() ) {                try {                    groupToReturn = new NNTPGroupImpl(groupFile);                    ContainerUtil.enableLogging(groupToReturn, getLogger());                    ContainerUtil.contextualize(groupToReturn, context);                    ContainerUtil.initialize(groupToReturn);                    repositoryGroups.put(groupName, groupToReturn);                } catch (Exception e) {                    getLogger().error("Couldn't create group object.", e);                    groupToReturn = null;                }            }        }        return groupToReturn;    }    /**     * @see org.apache.james.nntpserver.repository.NNTPRepository#getArticleFromID(String)     */    public NNTPArticle getArticleFromID(String id) {        try {            return articleIDRepo.getArticle(this,id);        } catch(Exception ex) {            getLogger().error("Couldn't get article " + id + ": ", ex);            return null;        }    }    /**     * @see org.apache.james.nntpserver.repository.NNTPRepository#createArticle(InputStream)     */    public void createArticle(InputStream in) {        StringBuffer fileBuffer =            new StringBuffer(32)                    .append(System.currentTimeMillis())                    .append(".")                    .append(Math.random());        File f = new File(tempPath, fileBuffer.toString());        FileOutputStream fout = null;        try {            fout = new FileOutputStream(f);            byte[] readBuffer = new byte[1024];            int bytesRead = 0;            while ( ( bytesRead = in.read(readBuffer, 0, 1024) ) > 0 ) {                fout.write(readBuffer, 0, bytesRead);            }            fout.flush();            fout.close();            fout = null;            boolean renamed = f.renameTo(new File(spool.getSpoolPath(),f.getName()));            if (!renamed) {                throw new IOException("Could not create article on the spool.");            }        } catch(IOException ex) {            throw new NNTPException("create article failed",ex);        } finally {            if (fout != null) {                try {                    fout.close();                } catch (IOException ioe) {                    // Ignored                }            }        }    }    class GroupFilter implements java.io.FilenameFilter {        public boolean accept(java.io.File dir, String name) {            if (getLogger().isDebugEnabled()) {                getLogger().debug(((definedGroupsOnly ? groupNameMap.containsKey(name) : true) ? "Accepting ": "Rejecting") + name);            }            return definedGroupsOnly ? groupNameMap.containsKey(name) : true;        }    }    /**     * @see org.apache.james.nntpserver.repository.NNTPRepository#getMatchedGroups(String)     */    public Iterator getMatchedGroups(String wildmat) {        File[] f = rootPath.listFiles(new AndFileFilter(new GroupFilter(), new AndFileFilter            (new DirectoryFileFilter(),new GlobFilenameFilter(wildmat))));        return getGroups(f);    }    /**     * Gets an iterator of all news groups represented by the files     * in the parameter array.     *     * @param f the array of files that correspond to news groups     *     * @return an iterator of news groups     */    private Iterator getGroups(File[] f) {        List list = new ArrayList();        for ( int i = 0 ; i < f.length ; i++ ) {            if (f[i] != null) {                list.add(getGroup(f[i].getName()));            }        }        return list.iterator();    }    /**     * @see org.apache.james.nntpserver.repository.NNTPRepository#getGroupsSince(Date)     */    public Iterator getGroupsSince(Date dt) {        File[] f = rootPath.listFiles(new AndFileFilter(new GroupFilter(), new AndFileFilter            (new DirectoryFileFilter(),new DateSinceFileFilter(dt.getTime()))));        return getGroups(f);    }    // gets the list of groups.    // creates iterator that concatenates the article iterators in the list of groups.    // there is at most one article iterator reference for all the groups    /**     * @see org.apache.james.nntpserver.repository.NNTPRepository#getArticlesSince(Date)     */    public Iterator getArticlesSince(final Date dt) {        final Iterator giter = getGroupsSince(dt);        return new Iterator() {                private Iterator iter = null;                public boolean hasNext() {                    if ( iter == null ) {                        if ( giter.hasNext() ) {                            NNTPGroup group = (NNTPGroup)giter.next();                            iter = group.getArticlesSince(dt);                        }                        else {                            return false;                        }                    }                    if ( iter.hasNext() ) {                        return true;                    } else {                        iter = null;                        return hasNext();                    }                }                public Object next() {                    return iter.next();                }                public void remove() {                    throw new UnsupportedOperationException("remove not supported");                }            };    }    /**     * @see org.apache.james.nntpserver.repository.NNTPRepository#getOverviewFormat()     */    public String[] getOverviewFormat() {        return overviewFormat;    }    /**     * Creates an instance of the spooler class.     *     * TODO: This method doesn't properly implement the Avalon lifecycle.     */    private NNTPSpooler createSpooler()             throws ConfigurationException {        String className = "org.apache.james.nntpserver.repository.NNTPSpooler";        Configuration spoolerConfiguration = configuration.getChild("spool");        try {            // Must be a subclass of org.apache.james.nntpserver.repository.NNTPSpooler            className = spoolerConfiguration.getAttribute("class");        } catch(ConfigurationException ce) {            // Use the default class.        }        try {            Object obj = getClass().getClassLoader().loadClass(className).newInstance();            // TODO: Need to support service            ContainerUtil.enableLogging(obj, getLogger());            ContainerUtil.contextualize(obj, context);            ContainerUtil.configure(obj, spoolerConfiguration.getChild("configuration"));            ContainerUtil.initialize(obj);            return (NNTPSpooler)obj;        } catch(ClassCastException cce) {            StringBuffer errorBuffer =                new StringBuffer(128)                    .append("Spooler initialization failed because the spooler class ")                    .append(className)                    .append(" was not a subclass of org.apache.james.nntpserver.repository.NNTPSpooler");            String errorString = errorBuffer.toString();            getLogger().error(errorString, cce);            throw new ConfigurationException(errorString, cce);        } catch(Exception ex) {            getLogger().error("Spooler initialization failed",ex);            throw new ConfigurationException("Spooler initialization failed",ex);        }    }}

⌨️ 快捷键说明

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