-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataUtils.java
More file actions
93 lines (78 loc) · 2.83 KB
/
DataUtils.java
File metadata and controls
93 lines (78 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.company;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class DataUtils {
static String Path = "src/com/company";
static String tcpTxtPath = "/pcapFiles/pcapTcpFiles.txt";
static String udpTxtPath = "/pcapFiles/pcapUdpFiles.txt";
static String pcapTcpDir = "/pcapFiles/pcapTcpFiles/";
static String pcapUdpDir = "/pcapFiles/pcapUdpFiles/";
static String getFileNameNoEx(String filename) {
if ((filename != null) && (filename.length() > 0)) {
int dot = filename.lastIndexOf('.');
if ((dot > -1) && (dot < (filename.length()))) {
return filename.substring(0, dot);
}
}
return filename;
}
static int byteArrayToIntReverse(byte[] small_packet){
int packetBodyLen = 0;
for(int i=3; i>=0; i--){
packetBodyLen = packetBodyLen*256 + (int)(small_packet[i]&0xff);
}
return packetBodyLen;
}
static int byteArrayToInt4(byte[] small_packet){
int packetBodyLen = 0;
for(int i=0; i<4; i++){
packetBodyLen = packetBodyLen*256 + (int)(((int)small_packet[i])&0xff);
//System.out.println((int)(((int)small_packet[i])&0xff));
}
return packetBodyLen;
}
static int byteArrayToInt2(byte[] var1) {
int var3 = (var1[0] & 255) * 256 + (var1[1] & 255);
return var3;
}
static byte[] cutBytes(byte[] packetBody, int start, int end){
byte[] packet = new byte[end-start];
for (int i = 0; i<(end - start); i++){
packet[i] = packetBody[i+start];
}
return packet;
}
static List<String> ReadTxt(String txtpath) {
List<String> pcapPath = new ArrayList<String>();
try{
File file = new File(txtpath);
if(file.isFile()&&file.exists()){
InputStreamReader read = new InputStreamReader(new FileInputStream(file));
BufferedReader bufferedReader = new BufferedReader(read);
String lineTXT = null;
while ((lineTXT=bufferedReader.readLine())!=null){
pcapPath.add(lineTXT);
}
read.close();
}else {
System.out.println("找不到指定的文件!");
}
}catch (Exception e){
System.out.println("读取文件内容操作出错");
e.printStackTrace();
}
return pcapPath;
}
public static String formatFloatNumber(double value) {
if(value != 0.00){
java.text.DecimalFormat df = new java.text.DecimalFormat("########0.000000");
return df.format(value);
}else{
return "0.00";
}
}
}