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

📄 webcountimpl.java

📁 一个完整的网络订餐系统
💻 JAVA
字号:
package com.util;

import java.io.File;
import java.io.PrintStream;
import javax.servlet.ServletContext;


public class WebCountImpl
{

    static WebCount webcount = null;
    private String fileName;
    private String bakFileName;

    public WebCountImpl()
    {
        fileName = "webcount1.wzp";
        bakFileName = "webcount_bak.wzp";
    }

    public WebCountImpl(ServletContext context)
    {
        fileName = "webcount1.wzp";
        bakFileName = "webcount_bak.wzp";
        String filePath = context.getRealPath("WEB-INF");
        fileName = filePath + File.separator + fileName;
        bakFileName = filePath + File.separator + bakFileName;
    }

    public WebCountImpl(String fileName, String bakfileName)
    {
        this.fileName = "webcount1.wzp";
        bakFileName = "webcount_bak.wzp";
        this.fileName = fileName;
        bakFileName = bakfileName;
    }

    public WebCount getNewWebCount()
    {
        return new WebCount();
    }

    public void initWebCount(WebCount webCount)
    {
        WebCountImpl _tmp = this;
        webcount = webCount;
        initWebCount();
    }

    public void initWebCount()
    {
        WebCountImpl _tmp = this;
        if(webcount == null)
            webcount = new WebCount();
        Serial serial = new Serial();
        File file1 = new File(fileName);
        File file2 = new File(bakFileName);
        try
        {
            serial.writeObjectToFile(file1, webcount);
            serial.writeObjectToFile(file2, webcount);
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
    }

    public WebCount getWebCount()
    {
        WebCountImpl _tmp = this;
        if(webcount == null)
        {
            Serial serial = new Serial();
            try
            {
                webcount = (WebCount)serial.readObjectFromFile(new File(fileName));
            }
            catch(Exception ex)
            {
                try
                {
                    webcount = (WebCount)serial.readObjectFromFile(new File(bakFileName));
                    serial.writeObjectToFile(new File(fileName), webcount);
                }
                catch(Exception ex1)
                {
                    initWebCount();
                }
            }
        }
        return webcount;
    }

    public void addCount()
    {
        _addCount();
    }

    private void _addCount()
    {
        WebCountImpl _tmp = this;
        if(webcount == null)
            webcount = getWebCount();
        webcount.addCount();
        if(webcount.getSumcount() % 10 == 0)
        {
            Serial serial = new Serial();
            try
            {
                serial.writeObjectToFile(new File(fileName), webcount);
                if(webcount.getSumcount() % 100 == 0)
                    serial.writeObjectToFile(new File(bakFileName), webcount);
            }
            catch(Exception ex)
            {
                System.out.println(ex.getMessage());
            }
        }
    }

}

⌨️ 快捷键说明

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