java - Transfering Base64 String over Http REST service with JSON response -


i have webservice returnds json response , json response contains both plain text , base64 encoded images , consuming service using android app implemented progress bar indicate progress .

implementing progress bar forces me use bufferedinputstream read response , update progress based on app reading .

the problem working fine , progress updating correctly, after collecting response , exiting while loop , try convert string json format using jsonobject. here code snippet

bufferedinputstream bis = new bufferedinputstream(responseentity.getcontent());             stringbuilder sb = new stringbuilder();             string line = null;             int total = 0 ;             int count = 0 ;             byte[] buffer = new byte[4096];             stringbuffer sbuffer = new stringbuffer();             stringwriter sw = new stringwriter();             string content = new string();              while((count = bis.read(buffer)) > 0){                 content += new string(buffer,charset.defaultcharset());                  total += count;                 publishprogress(""+(int )total*100/this.contentsize);                 log.i("updating",""+(int )total*100/this.contentsize);             }               bis.close();            // string content = new string(sb);             // log.i("serverrawresponse",content);             try {                 log.i("response_content",content.replaceall("\"", ""));                 responsestring = new jsonobject(new jsontokener(content.replaceall("\"", "\\\"")));                 //system.out.println(content);             } catch (jsonexception e) {                 e.printstacktrace();              } 

any please

try methods works me

httpresponse wsresponse = httpclient.execute(httppost); string response = getresponsebody(wsresponse.getentity()); jsonobject jobj = new jsonobject(response);  public string getresponsebody(final httpentity entity) throws ioexception, parseexception {          system.out.println("gen start : " + calendar.getinstance().gettimeinmillis());         if (entity == null) {             throw new illegalargumentexception("http entity may not null");         }          inputstream instream = entity.getcontent();          if (instream == null) {             return "";         }          if (entity.getcontentlength() > integer.max_value) {             throw new illegalargumentexception(              "http entity large buffered in memory");         }           stringbuilder buffer = new stringbuilder();          bufferedreader reader = new bufferedreader(new inputstreamreader(instream, http.utf_8));          string line = null;         try {             while ((line = reader.readline()) != null) {                 buffer.append(line);             }          } {             instream.close();             reader.close();         }          return buffer.tostring();      } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -