Posted on 2008-07-25 16:39
G_G 閱讀(2159)
評論(0) 編輯 收藏 所屬分類:
javaGeneral
package
?uu;
import
?java.io.BufferedReader;
import
?java.io.File;
import
?java.io.FileInputStream;
import
?java.io.FileOutputStream;
import
?java.io.InputStreamReader;
import
?java.io.OutputStreamWriter;
import
?java.util.ArrayList;
import
?java.util.HashMap;
import
?java.util.List;
import
?java.util.Map;
import
?java.util.regex.Pattern;
public
?
class
?MainExc?{
????
//
數(shù)據(jù)文本?
????
static
?String?filePath?
=
?
"
smsservice.data
"
;
????
//
輸出文本
????
static
?String?outfile?
=
?
"
outfile.html
"
;
????
//
輸出?文本格式
????
static
?String?charset?
=
?
"
GBK
"
;
????
//
數(shù)據(jù)邏輯?展現(xiàn)
????
static
?Map
<
Pattern,?String
>
?map?
=
?
new
?HashMap
<
Pattern,?String
>
();
????
static
?{
????????map.put(Pattern.compile(
"
^XZT
"
),?
"
sina
"
);
??????? 。。。。。
????}
????
//
類型定義
????
static
?Map
<
Pattern,?String
>
?maptype?
=
?
new
?HashMap
<
Pattern,?String
>
();
????
static
?{
????????maptype.put(Pattern.compile(
"
^3P45
"
),?
"
客戶端
"
);
????????maptype.put(Pattern.compile(
"
^6930
"
),?
"
圖表
"
);
??????? ......
????}
????
//
禁止展現(xiàn)
????
static
?List
<
Pattern
>
?listNo?
=
?
new
?ArrayList
<
Pattern
>
();
????
static
?{
????????listNo.add(Pattern.compile(
"
^9588Command$
"
));
????????listNo.add(Pattern.compile(
"
^5kjsCommand$
"
));
????????listNo.add(Pattern.compile(
"
^529901001011021$
"
));
????????listNo.add(Pattern.compile(
"
^529901001011022$
"
));
????}
????
????
????
public
?
static
?
void
?main(String[]?args)?
throws
?Exception?{
????????
//
?read
????????InputStreamReader?read?
=
?
new
?InputStreamReader(
????????????????
new
?FileInputStream(MainExc.
class
.getClassLoader().getResource(
????????????????????????filePath).getPath()),?charset);
????????
????????
//
?writer
????????
if
?(MainExc.
class
.getClassLoader().getResource(outfile)?
==
?
null
)?{
????????????
new
?File(MainExc.
class
.getClassLoader().getResource(
"
.
"
).getPath()
????????????????????
+
?
"
/outfile.html
"
).createNewFile();
????????}
????????OutputStreamWriter?writer?
=
?
new
?OutputStreamWriter(
????????????????
new
?FileOutputStream(MainExc.
class
.getClassLoader()
????????????????????????.getResource(outfile).getPath()),?charset);
????????
????????
//
?內(nèi)存?裝載?處
????????List
<
Map
<
String,?String
>>
?datas?
=
?
new
?ArrayList
<
Map
<
String,?String
>>
();
????????
????????
????????StringBuffer?buffer?
=
?
new
?StringBuffer();
????????BufferedReader?reader?
=
?
new
?BufferedReader(read);
????????String?stmp?
=
?
null
;
????????List
<
String
>
?colName?
=
?
new
?ArrayList
<
String
>
();
????????
//
得到?列名
????????
if
?((stmp?
=
?reader.readLine())?
!=
?
null
?
&&
?
!
stmp.trim().equals(
""
))?{
????????????
//
?split?-?>?Tab
????????????
for
?(String?stmp2?:?stmp.split(
"
????
"
))?{
????????????????colName.add(stmp2);
????????????}
????????}
????????
????????
//
列數(shù)據(jù)收集
????????
while
?((stmp?
=
?reader.readLine())?
!=
?
null
?
&&
?
!
stmp.trim().equals(
""
))?{
????????????Map
<
String,?String
>
?data?
=
?
new
?HashMap
<
String,?String
>
();
????????????String[]?sdata?
=
?stmp.split(
"
????
"
);
????????????
for
?(
int
?i?
=
?
0
;?i?
<
?colName.size();?i
++
)?{
????????????????data.put(colName.get(i),?sdata[i]);
????????????}
????????????datas.add(data);
????????}
????????
????????
//
?writer
????????writer.append(
"
<center><table??border>\n
"
);
????????writer.append(
"
<tr>
"
?
+
?
"
<td>通道伙伴</td>
"
?
+
?
"
<td>指令</td>
"
?
+
?
"
<td>長號碼</td>
"
????????????????
+
?
"
<td>資費</td>
"
?
+
?
"
<td>業(yè)務(wù)類型(圖表/客戶端)</td>
"
?
+
?
"
</tr>\n
"
);
????????
//
?通道伙伴?指令?長號碼?資費?業(yè)務(wù)類型(圖表?客戶端?)
????????wfor:?
for
?(Map
<
String,?String
>
?mtmp?:?datas)?{
????????????
for
?(Pattern?ptmp?:?listNo)?{
????????????????
if
?(ptmp.matcher(mtmp.get(
"
command
"
)).find())?{
????????????????????
continue
?wfor;
????????????????}
????????????}
????????????String?hzhb?
=
?
""
;
????????????
for
?(Pattern?ptmp?:?map.keySet())?{
????????????????
if
?(ptmp.matcher(mtmp.get(
"
command
"
)).find())?{
????????????????????hzhb?
=
?map.get(ptmp);
????????????????}
????????????}
????????????String?type?
=
?
""
;
????????????
for
?(Pattern?ptmp?:?maptype.keySet())?{
????????????????
if
?(ptmp.matcher(mtmp.get(
"
command
"
)).find())?{
????????????????????type?
=
?maptype.get(ptmp);
????????????????}
????????????}
????????????writer.append(
"
<tr>
"
?
+
?
"
<td?align='center'>
"
?
+
?hzhb?
+
?
"
</td>
"
????????????????????
+
?
"
<td?align='center'>
"
?
+
?mtmp.get(
"
command
"
)?
+
?
"
</td>
"
????????????????????
+
?
"
<td?align='center'>
"
?
+
?mtmp.get(
"
num
"
)?
+
?
"
</td>
"
????????????????????
+
?
"
<td?align='center'>
"
?
+
?mtmp.get(
"
money
"
)?
+
?
"
</td>
"
????????????????????
+
?
"
<td?align='center'>
"
?
+
?type?
+
?
"
</td>
"
?
+
?
"
</tr>\n
"
);
????????}
????????writer.append(
"
</table></center>\n
"
);
????????
//
?save?
????????writer.flush();
????????writer.close();
????}
}