當前位置:首頁 » 編程語言 » java解析報文

java解析報文

發布時間: 2022-08-11 05:13:15

『壹』 如何實現java解析網路協議報文(類似Wireshark那樣,或者有沒有開源的包供調用)

從http://netresearch.ics.uci.e/kfujii/Jpcap/doc/index.html 找到JPcap。JPcap 是一個能夠捕獲、發送網路數據包的Java 類庫包。這個包用到了LibPcap 和原始套接字API。

『貳』 java 解析數據報文

數據報文有很多協議的
你要分析的那種?
其實那種都大同小異
用DatagramSocket類和DatagramPacket類
socket建立連接
packet取得數據報
然後對不同的類型進行分析咯

『叄』 JAVA解析發送tcp ip報文

JAVA 寫一個SOCKET 伺服器,接收、處理單片機遞交上來的數據

通過文字輸入流,直接可以當字元處理的。也很方便輸出返饋。

『肆』 heapbuffer報文java怎麼解析

heap buffer 和 direct buffer區別

在Java的NIO中,我們一般採用ByteBuffer緩沖區來傳輸數據,一般情況下我們創建Buffer對象是通過ByteBuffer的兩個靜態方法:

ByteBuffer.allocate(int capacity);
ByteBuffer.wrap(byte[] array);

查看JDK的NIO的源代碼關於這兩個部分:

/**allocate()函數的源碼**/
public static ByteBuffer allocate(int capacity) {
if (capacity < 0)
throw new IllegalArgumentException();
return new HeapByteBuffer(capacity, capacity);
}

/**wrap()函數的源碼**/
public static ByteBuffer wrap(byte[] array) {
return wrap(array, 0, array.length);
}
//
public static ByteBuffer wrap(byte[] array,
int offset, int length)
{
try {
return new HeapByteBuffer(array, offset, length);
} catch (IllegalArgumentException x) {
throw new IndexOutOfBoundsException();
}
}

我們可以很清楚的發現,這兩個方法都是實例化HeapByteBuffer來創建的ByteBuffer對象,也就是heap buffer. 其實除了heap buffer以外還有一種buffer,叫做direct buffer。我們也可以創建這一種buffer,通過ByteBuffer.allocateDirect(int capacity)方法,查看JDK源碼如下:

public static ByteBuffer allocateDirect(int capacity) {
return new DirectByteBuffer(capacity);
}

我們發現該函數調用的是DirectByteBuffer(capacity)這個類,這個類就是創建了direct buffer。

『伍』 如何實現java解析網路協議報文

普通參數:
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

文件參數:
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

參數實體的最後一行是: --加上boundary加上--,最後換行,這里的 格式即為: --OCqxMF6-JxtxoMDHmoG5W5eY9MGRsTBp--。

模擬文件上傳請求
public static void uploadFile(String fileName) {
try {
// 換行符
final String newLine = "\r\n";
final String boundaryPrefix = "--";
// 定義數據分隔線
String BOUNDARY = "========7d4a6d158c9";
// 伺服器的域名
URL url = new URL("www.myhost.com");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 設置為POST情
conn.setRequestMethod("POST");
// 發送POST請求必須設置如下兩行
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
// 設置請求頭參數
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Charsert", "UTF-8");
conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
OutputStream out = new DataOutputStream(conn.getOutputStream());
// 上傳文件
File file = new File(fileName);
StringBuilder sb = new StringBuilder();
sb.append(boundaryPrefix);
sb.append(BOUNDARY);
sb.append(newLine);
// 文件參數,photo參數名可以隨意修改
sb.append("Content-Disposition: form-data;name=\"photo\";filename=\"" + fileName
+ "\"" + newLine);
sb.append("Content-Type:application/octet-stream");
// 參數頭設置完以後需要兩個換行,然後才是參數內容
sb.append(newLine);
sb.append(newLine);
// 將參數頭的數據寫入到輸出流中
out.write(sb.toString().getBytes());
// 數據輸入流,用於讀取文件數據
DataInputStream in = new DataInputStream(new FileInputStream(
file));
byte[] bufferOut = new byte[1024];
int bytes = 0;
// 每次讀1KB數據,並且將文件數據寫入到輸出流中
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
// 最後添加換行
out.write(newLine.getBytes());
in.close();
// 定義最後數據分隔線,即--加上BOUNDARY再加上--。
byte[] end_data = (newLine + boundaryPrefix + BOUNDARY + boundaryPrefix + newLine)
.getBytes();
// 寫上結尾標識
out.write(end_data);
out.flush();
out.close();
// 定義BufferedReader輸入流來讀取URL的響應
// BufferedReader reader = new BufferedReader(new InputStreamReader(
// conn.getInputStream()));
// String line = null;
// while ((line = reader.readLine()) != null) {
// System.out.println(line);
// }
} catch (Exception e) {
System.out.println("發送POST請求出現異常!" + e);
e.printStackTrace();
}
}

『陸』 java解析報文

ByteBuffer bb = ByteBuffer.wrap(data, offset, length);
if (bb.remaining() < MIN_HEADER_LENGTH) {
return this;
}

this.opCode = bb.get();
this.transactionId = bb.getInt();

按照這種節奏搞吧,這個很簡單的啊,拿到BYTEBUFFER以後,一點一點的處理byte。

『柒』 誰能幫我做個java 報文解析類。

很簡單。
#include<stdio.h>
void main()
{int m,n,p=0,i=1;
scanf("d%,%d",&m,&n);
for(i;i<=m;i++)
{p+=i;}
for(i=1;i<=n;i++)
{p+=i;}
printf("%d\n",p);
}
我大致寫了下,思路很簡

『捌』 java怎麼解析文本文件中的soap報文

首先,通過流的方式讀取txt中soap報文字元串。第二步,通過dom4j讀取soap報文字元串進行解析(常規的xml解析)

『玖』 java xml報文解析,下面是從其它平台傳過來的一個xml報文,小弟從來沒涉及這塊,求解析方法,求大神指點

自己去搜一個叫dom4j的東西……這是java的一個第三方工具包,用來解析xml的

『拾』 請問java中解析報文有什麼用,我每次應聘的時候,考官都問我以前做沒做過報文

報文都是按照你指定的格式來進行發送的數據,也就是說你想怎麼定義,就怎麼定義,比如說你看到的這些0-327630-94-18-12-205646-,那麼他可能是,0協議,327630個位元組數,然後指定開始的94協議,18具體的內容,所以說呢,報文是2台計算機通訊所用的協議。你只有弄懂了協議,你才能看的懂這些報文的意思,當然不可能讓你手動翻譯出來了。

熱點內容
安卓手機怎麼調節字體顏色 發布:2024-04-24 05:43:14 瀏覽:409
金蝶軟體如何下載加密伺服器 發布:2024-04-24 05:34:21 瀏覽:337
activex執行腳本 發布:2024-04-24 05:34:15 瀏覽:465
195的源碼 發布:2024-04-24 05:33:01 瀏覽:669
巨盛老年機的統一密碼是什麼 發布:2024-04-24 05:32:05 瀏覽:703
sql時間最大 發布:2024-04-24 05:21:14 瀏覽:17
linuxcpumysql 發布:2024-04-24 05:10:40 瀏覽:903
如何才能使郵件伺服器高效穩定地工作 發布:2024-04-24 04:30:55 瀏覽:462
sql數字開頭的 發布:2024-04-24 04:29:17 瀏覽:63
c電梯調度演算法 發布:2024-04-24 04:15:34 瀏覽:787