I am decoding http packets.
And I faced a problem that chunk problem.
When I get a http packet it has a header and body.
When transefer-encoding is chunked I don’t know what to do ?
Is there a useful API or class for dechunk the data in JAVA ?
And if someone , experienced about http decoding , please show me a way how to do this ?
Use a fullworthy HTTP client like Apache HttpComponents Client or just the Java SE provided
java.net.URLConnection(mini tutorial here). Both handles it fully transparently and gives you a “normal”InputStreamback. HttpClient in turn also comes with aChunkedInputStreamwhich you just have to decorate yourInputStreamwith.If you really insist in homegrowing a library for this, then I’d suggest to create a class like
ChunkedInputStream extends InputStreamand write logic accordingly. You can find more detail how to parse it in this Wikipedia article.