没想清楚就下笔 白写了

<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --> package  com.roadway.edmail.fboperate;

import  java.io.File;
import  java.io.FileInputStream;
import  java.io.FileOutputStream;
import  java.util.ArrayList;
import  java.util.List;

import  org.apache.log4j.Logger;

import  com.roadway.edmail.fboperate.model.OperateModel;
import  com.roadway.edmail.util.StrUtil;
import  com.roadway.edmail.util.SysParameters;

public   class  OperateModelCacheHelper
{
    
/**  日志记录  */
    
private   static  Logger logger  =  Logger
            .getLogger(OperateModelCacheHelper.
class .getName());
    
    
/**  未处理的操作模型的文件的路径  */
    
private   static  String operatedModelPath  =  SysParameters.basicPath
            
+   " operatingModel.txt " ;;
    
    
/**  已经处理的操作模型的文件的路径  */
    
private   static  String operatingModelPath  =  SysParameters.basicPath
            
+   " operatedModel.txt " ;
    
    
/**
     * 本方法用于把一个操作模型存入到临时文件
     * 
     * 
@param  filePath
     *            文件的路径
     * 
@param  model
     *            对像模型
     
*/
    
public   static   synchronized   void  model2File(String filePath,
            OperateModel model, 
boolean  isAppend)
    {
        
/**  如果对象为NULL  */
        
if  (model  ==   null )
        {
            
return ;
        }
        File operatingFile 
=   new  File(filePath);
        
/**  如果文件不存在,退出程序  */
        
if  ( ! operatingFile.exists())
        {
            
return ;
        }
        FileOutputStream fos 
=   null ;
        
try
        {
            fos 
=   new  FileOutputStream(operatingFile, isAppend);
            fos.write(model.toString().getBytes());
        }
        
catch  (Exception ex)
        {
            
/**  把异常信息加入到日志  */
            OperateModelCacheHelper.logger.error(StrUtil.getExceptionInfo(ex,
                    
" edm_h " ));
        }
        
finally
        {
            
try
            {
                
/**  关闭输入输出流  */
                fos.close();
            }
            
catch  (Exception e)
            {   

            }
        }
    }
    
    
/**
     * 
@param  filePath
     * 
@return
     
*/
    
public   static   synchronized  List < OperateModel >  file2Models(String filePath)
    {
        
/**  装models的集合  */
        List
< OperateModel >  models  =   new  ArrayList < OperateModel > ();
        File operatingFile 
=   new  File(filePath);
        
/**  如果文件不存在,退出程序  */
        
if  ( ! operatingFile.exists())
        {
            
return  models;
        }
        StringBuffer content 
=   new  StringBuffer();
        FileInputStream fis 
=   null ;
        
try
        {
            fis 
=   new  FileInputStream(operatingFile);
            
byte [] buffer  =   new   byte [ 1024 ];
            
int  byteRead  =   0 ;
            
while  ((byteRead  =  fis.read(buffer,  0 , buffer.length))  !=   - 1 )
            {
                content.append(
new  String(buffer,  0 , byteRead));
            }
        }
        
catch  (Exception ex)
        {
            
/**  把异常信息加入到日志  */
            OperateModelCacheHelper.logger.error(StrUtil.getExceptionInfo(ex,
                    
" edm_h " ));
        }
        
finally
        {
            
try
            {
                fis.close();
            }
            
catch  (Exception ex)
            {}
        }
        String contentStr 
=  content.toString();
        
/**  记录日志  */
        OperateModelCacheHelper.logger.debug(
" file2Model的内容为: "   +  contentStr);
        String[] strModels 
=  contentStr.split( " \n\r " );
        
        OperateModel model 
=   null ;
        
for  ( int  len  =   0 ; len  <  strModels.length; len ++ )
        {
            String[] infos 
=  strModels[len].split( " [,] " );
            
if  (infos.length  ==   3 )
            {
                model 
=   new  OperateModel(infos[ 0 ], infos[ 1 ], infos[ 3 ]);
                models.add(model);
            }
        }
        
return  models;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值