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

📄 localnewsdb.java

📁 java高级使用教程 全书一共分六章
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    BufferedReader br = new BufferedReader( new FileReader(
		SPOOLDIR + "/" + group.getName().replace( '.', '/' ) +
		"/.overview" ) );
	    while ( true )
		{
		String line = br.readLine();
		if ( line == null )
		    break;
		int tab = line.indexOf( '\t' );
		int artNum;
		try
		    {
		    artNum = Integer.parseInt( line.substring( 0, tab ) );
		    }
		catch ( NumberFormatException e )
		    {
		    continue;
		    }
		String[] overviewEntry =
		    Utils.splitStr( line.substring( tab + 1 ), '\t' );
		if ( overviewEntry.length != overviewFmt.length )
		    continue;   // ignore malformed lines
		overviewCache.addEntry( overviewEntry, group, artNum );
		}
	    br.close();
	    }
	catch ( IOException ignore ) {}
	}

    /// Get an enumeration of all the groups.
    // @exception NewsDbException if something goes wrong
    public Enumeration getGroups() throws NewsDbException
	{
	checkGroups();
	return groupTable.elements();
	}

    /// Get an enumeration of all groups created after a given time.
    // @exception NewsDbException if something goes wrong
    public Enumeration getGroups( long since ) throws NewsDbException
	{
	// !!!
	throw new NewsDbException( "not implemented yet" );
	}

    /// Get an enumeration of all groups created after a given time that match
    // a given distributions pattern.
    // @exception NewsDbException if something goes wrong
    public Enumeration getGroups( long since, String distsPat ) throws NewsDbException
	{
	// !!!
	throw new NewsDbException( "not implemented yet" );
	}

    /// Get an enumeration of all message-ids received after a given time
    // in groups matching the given pattern.
    // @exception NewsDbException if something goes wrong
    public Enumeration getMessageIds( String groupsPat, long since ) throws NewsDbException
	{
	// !!!
	throw new NewsDbException( "not implemented yet" );
	}

    /// Get an enumeration of all message-ids received after a given time
    // in groups matching the given pattern, that also match the
    // given distributions pattern.
    // @exception NewsDbException if something goes wrong
    public Enumeration getMessageIds( String groupsPat, long since, String distsPat ) throws NewsDbException
	{
	// !!!
	throw new NewsDbException( "not implemented yet" );
	}

    /// Post an article.
    // @exception NewsDbException if something goes wrong
    public void post( String artText ) throws NewsDbException
	{
	// !!!
	throw new NewsDbException( "not implemented yet" );
	}

    /// Shut down the news database.
    public void close()
	{
	// !!!
	}


    /// Initializer for paths.
    // We try to guess where the netnews files are.  If we can't
    // find a vital one, we throw an exception.
    // @exception NewsDbException if something goes wrong
    private void initializePaths() throws NewsDbException
	{
	if ( ( new File( SPOOLDIR_1 ) ).exists() )
	    SPOOLDIR = SPOOLDIR_1;
	else if ( ( new File( SPOOLDIR_2 ) ).exists() )
	    SPOOLDIR = SPOOLDIR_2;
	else
	    throw new NewsDbException( "can't find spooldir" );

	if ( LIBDIR_1 != null && ( new File( LIBDIR_1 ) ).exists() )
	    LIBDIR = LIBDIR_1;
	else
	    {
	    try
		{
		LIBDIR = ( new UnixUser( LIBDIR_USER_1 ) ).getHomeDir();
		}
	    catch ( IOException e )
		{
		try
		    {
		    LIBDIR = ( new UnixUser( LIBDIR_USER_2 ) ).getHomeDir();
		    }
		catch ( IOException f )
		    {
		    throw new NewsDbException( "can't find libdir" );
		    }
		}
	    }

	if ( AUXLIBDIR_1 != null && ( new File( AUXLIBDIR_1 ) ).exists() )
	    AUXLIBDIR = AUXLIBDIR_1;
	else
	    AUXLIBDIR = LIBDIR;

	// Required files.
	ACTIVE = new File( LIBDIR + "/" + "active" );
	if ( ! ACTIVE.exists() )
	    {
	    ACTIVE = new File( AUXLIBDIR + "/" + "active" );
	    if ( ! ACTIVE.exists() )
		throw new NewsDbException( "can't find active" );
	    }
	HISTORY = new File( LIBDIR + "/" + "history" );
	if ( ! HISTORY.exists() )
	    {
	    HISTORY = new File( AUXLIBDIR + "/" + "history" );
	    if ( ! HISTORY.exists() )
		throw new NewsDbException( "can't find history" );
	    }

	// Optional files.
	NEWSGROUPS = new File( LIBDIR + "/" + "newsgroups" );
	if ( ! NEWSGROUPS.exists() )
	    NEWSGROUPS = null;
	NNRP_ACCESS = new File( LIBDIR + "/" + "nnrp.access" );
	if ( ! NNRP_ACCESS.exists() )
	    NNRP_ACCESS = null;
	ACTIVE_TIMES = new File( LIBDIR + "/" + "active.times" );
	if ( ! ACTIVE_TIMES.exists() )
	    ACTIVE_TIMES = null;
	DISTRIBUTIONS = new File( LIBDIR + "/" + "distributions" );
	if ( ! DISTRIBUTIONS.exists() )
	    DISTRIBUTIONS = null;
	DISTRIB_PATS = new File( LIBDIR + "/" + "distrib.pats" );
	if ( ! DISTRIB_PATS.exists() )
	    DISTRIB_PATS = null;
	OVERVIEW_FMT = new File( LIBDIR + "/" + "overview.fmt" );
	if ( ! OVERVIEW_FMT.exists() )
	    OVERVIEW_FMT = null;
	}


    /// Read the list of groups, if necessary.
    private synchronized void checkGroups() throws NewsDbException
	{
	checkGroupDescs();	// check group descriptions cache too
	long now = System.currentTimeMillis();
	if ( groupTable != null &&
	     now - groupsFetched < NnrpdUtils.INT_CHECKGROUPS )
	    return;
	groupTable = new Hashtable();
	groupsFetched = now;
	String line;
	String[] words;
	String groupName;
	int lastArtNum, firstArtNum;
	char flag;
	NewsDbGroup group;
	try
	    {
	    BufferedReader br =
		new BufferedReader( new FileReader( ACTIVE ) );
	    while ( true )
		{
		line = br.readLine();
		if ( line == null )
		    break;
		words = Utils.splitStr( line );
		groupName = words[0];
		try
		    {
		    lastArtNum = Integer.parseInt( words[1] );
		    firstArtNum = Integer.parseInt( words[2] );
		    }
		catch ( NumberFormatException e )
		    {
		    continue;
		    }
		flag = words[3].charAt( 0 );
		group = new NewsDbGroup(
		    dbStamp, groupName, lastArtNum - firstArtNum + 1,
		    firstArtNum, lastArtNum, flag,
		    (String) groupDescsTable.get( groupName ) );
		groupTable.put( group.getName(), group );
		}
	    br.close();
	    }
	catch ( IOException e )
	    {
	    throw new
		NewsDbException( "problem reading groups: " + e );
	    }
	}

    /// Read the list of group descriptions, if necessary.
    private synchronized void checkGroupDescs() throws NewsDbException
	{
	long now = System.currentTimeMillis();
	if ( groupDescsTable != null &&
	     now - groupDescsFetched < NnrpdUtils.INT_CHECKGROUPDESCS )
	    return;
	groupDescsFetched = now;
	groupDescsTable = new Hashtable();
	if ( NEWSGROUPS == null )
	    return;
	String line, groupName, groupDesc;
	int ws, nws;
	try
	    {
	    BufferedReader br =
		new BufferedReader( new FileReader( NEWSGROUPS ) );
	    while ( true )
		{
		line = br.readLine();
		if ( line == null )
		    break;
		ws = Utils.strCSpan( line, " \t" );
		nws = ws + Utils.strSpan( line, " \t", ws );
		groupName = line.substring( 0, ws );
		groupDesc = line.substring( nws );
		groupDescsTable.put( groupName, groupDesc );
		}
	    br.close();
	    }
	catch ( IOException e )
	    {
	    throw new
		NewsDbException( "problem reading group descriptions: " + e );
	    }
	}

    }

⌨️ 快捷键说明

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