Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Confusion about Chunked length in HTTPPacket

Hao Hu
2010-11-25
2013-05-02
  • Hao Hu
    Hao Hu
    2010-11-25

    Hi everyone,
    When I test the Cyberlink sdk with WD TV live, I have got some problem with HTTP "chunked" response. I have read the source code from the HTTPPacket.java and got confused with the source code handling the chunked length.
    In the set(InputStream in, boolean onlyHeaders) method, I got the line:
    contentLen = Long.parseLong(new String(chunkSizeLine.getBytes(), 0, chunkSizeLine.length()-2), 16);
    why does it calculate the length in such way?
    http://en.wikipedia.org/wiki/Chunked_transfer_encoding#Example shows an example.
    Thanks very much in advance.
    Cheers,
    Hao

     
  • bebopfreak
    bebopfreak
    2010-11-25

    Because it's buggy. See Tracker Bugs

     
  • Hao Hu
    Hao Hu
    2010-11-25

    Thanks for your reply, I just wonder it is a buggy, why not fix it?

     
  • Satoshi Konno
    Satoshi Konno
    2010-12-07

    Hi Hao,

    I checked your report, and I understood that the patch line is wrong.
    I will change this line as the following from now.

    ===================================================================
    -- HTTPPacket.java (revision 164)
    +++ HTTPPacket.java (working copy)
    @@ -229,7 +229,7 @@
    try {
    String chunkSizeLine = readLine(reader);
    // Thanks for Lee Peik Feng <pflee@users.sourceforge.net> (07/07/05)
    - contentLen = Long.parseLong(new String(chunkSizeLine.getBytes(), 0, chunkSizeLine.length()-2), 16);
    + contentLen = chunkSizeLine ? Long.parseLong(chunkSizeLine.trim(), 16) : 0;
    }
    catch (Exception e) {};
    }

    Thanks for your report :-)