Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Chunked transfer encoding problem

Chunked transfer encoding problem

Scheduled Pinned Locked Moved Java
help
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kharfax
    wrote on last edited by
    #1

    Hi guys, I think I'm going to lose my mind with this, I cant make my chunked transfer manager to work right. The problem I'm having is that reading the amount of data specified in the chunk-size, I end up having the next chunk size inside the body, so, when I call the next getchunksize, it fails. The first call to getChunkSize() works great and I get the size value as expected. The BufferedReader is connected to the sock s = new Socket(connectTo, portNum); sIn = new BufferedReader(new InputStreamReader(s.getInputStream()) ); Thanks a lot guys, I hope any of you understands what's going on... private String processChunked(BufferedReader sIn, String newData) throws IOException { newData += LINEBREAK; // Let's separate header form body int size = 0; String body = new String(); size = getChunkSize(sIn); while(size > 0) { body = getChunkData(sIn, size); size = getChunkSize(sIn); newData += body; body = ""; } return newData; } private String getChunkData(BufferedReader sIn, int lenght) throws IOException { int val = 0; String res = new String(); char chr = ' '; for(int i= 0; i val = sIn.read(); if(val == -1) break; chr = (char)val; res += Character.valueOf(chr).toString(); } return res; } private int getChunkSize(BufferedReader sIn) throws IOException { char chr = ' ', prvChr = ' '; int val = 0; String tmpSize = new String(); int size = 0; int readed = 0; do { //Read chunk size prvChr = chr; val = sIn.read(); if (val == -1) { break; } readed++; chr = (char) val; tmpSize += Character.valueOf(chr).toString(); } while (prvChr != '\r' && chr != '\n'); // calculate chunk size if(tmpSize.indexOf(";") != -1) { //remove chunk extension tmpSize = tmpSize.substring(0, tmpSi

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups