📄 fileparserutil.java
字号:
/**
* @(#)FileParserUtil.java 10:10:55 2006-6-27
*
* Copyright (c) 2006 Datang Mobile Co.Ltd
* All right reserved.
*/
package com.datangmobile.oss.omc.pc.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import com.datangmobile.oss.omc.common.exception.NeaException;
import com.datangmobile.oss.omc.common.server.cm.CmConst;
import com.datangmobile.oss.omc.pc.PmConst;
import com.datangmobile.oss.platform.util.ILogger;
import com.datangmobile.oss.platform.util.ModuleLogger;
/**
* 配置文件解析工具类
* @author wangwei4
* @version 0.1
*
* 增加sortByTableName()方法<br>
* 根据tableName进行分类
* @author wuwei
* @version 0.2
*
* @version 3.2.2.2.0 chenhuanxiang 2007-5-9 writeAttrData()和readAttrData()做修以支持ipv4、ipv6、mac等datatype
* @version 3.2.2.5.0 chenhuanxiang 2007-6-12 BUGCN00016833,写文件时,对于需要补充的字符不应该简单的补0,但可以补属性最小值
* @version 3.2.2.9.0 chenhuanxiang 2007-6-29 解决中文乱码bug,charSet=UTF8
*/
public class FileParserUtil {
/**
* 日志记录器
*/
private static final ILogger log = ModuleLogger.getPmLogger()
.getOperLogger();
// 文件缓存大小
public final static int FILEBUFFER_SIZE = 1024;
/**
* 将指定文件列表中所有文件压缩成一个文件
* @param pFileNameList 文件列表
* @return String 被压缩的文件名称
*/
public static String zipFile(ArrayList<String> pFileNameList, String pDirName, String pType) throws IOException{
//Create a buffer for reading the files
byte[] buf = new byte[FileParserUtil.FILEBUFFER_SIZE];
// Create the ZIP file
String outFilename = "am.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(pDirName + outFilename));
try{
//Compress the files
for(String i : pFileNameList){
FileInputStream in = new FileInputStream(pDirName+i);
try{
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(i));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
//Complete the entry
out.closeEntry();
}finally{
in.close();
}
}
return outFilename;
}finally{
out.close();
}
}
/**
* 将指定文件解压<br>
* 2006-8-15 modified by wuwei 修改接口,传入参数分为目录名以及该目录下的文件名<br>
* 方便解压缩后的文件放在该目录下<br>
* @param dir 目录名
* @param file 文件名
* @return 解压后文件名列表
* @exception IOException
*/
public static ArrayList<String> unzipFile(String dir,String file) throws IOException{
BufferedOutputStream dest = null;
BufferedInputStream is = null;
FileOutputStream fos = null;
ZipEntry entry;
ArrayList<String> fileNameList = null;
byte[] data;
ZipFile zipfile = new ZipFile(dir+file);
int count;
try{
Enumeration e = zipfile.entries();
fileNameList = new ArrayList<String>();
while(e.hasMoreElements()) {
entry = (ZipEntry) e.nextElement();
fileNameList.add(dir+entry.getName());
try{
is = new BufferedInputStream(zipfile.getInputStream(entry));
fos = new FileOutputStream(dir+entry.getName());
dest = new BufferedOutputStream(fos, FileParserUtil.FILEBUFFER_SIZE);
data = new byte[FileParserUtil.FILEBUFFER_SIZE];
while ((count = is.read(data, 0, FileParserUtil.FILEBUFFER_SIZE))!= -1){
dest.write(data, 0, count);
}
dest.flush();
}finally{
if(null!=dest){
dest.close();
dest = null;
}
if(null!=fos){
fos.close();
fos = null;
}
if(null!=is){
is.close();
is = null;
}
}
}//end while
data = null;
return fileNameList;
}
finally{
zipfile.close();
}
}
/**
* 根据linkId以及网元类型,构成网元的DN RNC的dn形式 RAN=?,RNC=? HLR的dn形式 HLR=? NODEB的dn形式
* RAN=?,NODEB=? 对于核心网的GGSN SGSN WGW MSCSVR以后再考虑
*
* 如果根据文件名得不到网元类型,则抛出NeaException
*
* @param filename
* @return
* @throws NeaException
*/
public static String getNeDn(String filename) {
String linkId = null;
String neType = null;
String[] rds = filename.split(PmConst.PM_DATA_FILE_SEPARATOR);
/*
* liuyuan,2007-4-24 性能数据文件中网元类型为小写,所以去除原来改为大写的方法
* 网元ID为UINT16类型,表示为16进制,所以需要转换成10进制的形式
*
*/
// neType = rds[1].toUpperCase();
neType = rds[1];
linkId = rds[2].substring(0, 4);
linkId = Integer.parseInt(linkId, 16) + "";
/*
* liuyuan,2007-4-24 性能数据文件中网元类型为小写,所以定义了网元类型的小写常量 加入了GGSN SGSN
*/
if (neType.equals(PmConst.NETYPE_RNC)) {
return CmConst.RAN_NAME + CmConst.DN_LINK + linkId
+ CmConst.DN_SEPERATOR + CmConst.RNC_NAME + CmConst.DN_LINK
+ linkId;
} else if (neType.equals(PmConst.NETYPE_HLR)) {
return CmConst.HLR_NAME + CmConst.DN_LINK + linkId;
} else if (neType.equals(PmConst.NETYPE_NODEB)) {
return CmConst.RAN_NAME + CmConst.DN_LINK + linkId
+ CmConst.DN_SEPERATOR + CmConst.NODEB_NAME
+ CmConst.DN_LINK + linkId;
} else if (neType.equals(PmConst.NETYPE_GGSN)) {
return CmConst.GGSN_NAME + CmConst.DN_LINK + linkId;
} else if (neType.equals(PmConst.NETYPE_SGSN)) {
return CmConst.SGSN_NAME + CmConst.DN_LINK + linkId;
} else {
log.error(FileParserUtil.class, "the netype of filename "
+ filename + " is not ne");
return null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -