Thursday, August 26, 2010

[android-developers] Re: String being truncated when its long

Hi Jake,

I was actually doing this without the response handler. I tried that
one only when I started facing this problem. But the result is the
same.

On Aug 26, 5:21 pm, Jake Radzikowski <radzikowski.j...@gmail.com>
wrote:
> Could you try removing the responseHandler?
>
> On Thu, Aug 26, 2010 at 4:13 PM, Achanta <krishna.acha...@gmail.com> wrote:
> > I Tested your suggestions by setting UTF-8 and I also tried the same
> > by removing the length 8000. But it still does the same thing.
> > Thank you for the response though.
>
> > This thing is driving me nuts.
>
> > On Aug 26, 4:58 pm, Jake Radzikowski <radzikowski.j...@gmail.com>
> > wrote:
> > > reader = new BufferedReader(new InputStreamReader(inputStream), 8000);
> > I'm
> > > gunna guess that 8000 has something to do with it :). I usually use the
> > > following:
>
> > > reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
>
> > > On Thu, Aug 26, 2010 at 3:40 PM, Achanta <krishna.acha...@gmail.com>
> > wrote:
>
> > > > I am trying to get a JSON response from our server and the response
> > > > string seems is always being truncated when the string length reaches
> > > > to around 5525 characters.
>
> > > > HttpClient httpClient = new DefaultHttpClient();
> > > > HttpPost post = new HttpPost(URL);
> > > > ResponseHandler<String> responseHandler= new BasicResponseHandler();
> > > > String testResponse = httpClient.execute(post, responseHandler);
>
> > > > I also tried this by using HttpEntity and reading the response stream.
> > > > But that also truncates the string at approximately that length.
>
> > > >            HttpClient httpClient = new DefaultHttpClient();
> > > >            HttpPost post = new HttpPost(URL);
> > > > //          HttpGet get = new HttpGet(URL);
>
> > > >            HttpResponse response = null;
> > > >            HttpEntity entity = null;
> > > >            InputStream inputStream = null;
> > > >            BufferedReader reader = null;
> > > >            String result = "";
> > > >            try {
> > > >                response = (HttpResponse)httpClient.execute(post);
> > > >                entity = response.getEntity();
> > > >                if(entity != null){
> > > >                    inputStream = entity.getContent();
> > > >                }
> > > >                reader = new BufferedReader(new
> > > > InputStreamReader(inputStream), 8000);
> > > >                StringBuffer builder = new StringBuffer("");
> > > >                String line = reader.readLine();
> > > >                while(line != null){
> > > >                    Log.v(tag, "int max::::::::: "+Integer.MAX_VALUE);
> > > >                    Log.v(tag, "LINE::::::::: "+line
> > > > +reader.toString());
> > > >                    Log.v(tag, "reader::::::::: "+reader.toString());
> > > >                    builder.append(line+"\n");
> > > >                    line = reader.readLine();
> > > >                }
> > > >                inputStream.close();
> > > >                result = builder.toString();
> > > >            } catch (ClientProtocolException e) {
> > > >                e.printStackTrace();
> > > >            } catch (IOException e) {
> > > >                e.printStackTrace();
> > > >            } finally{
> > > >                if(inputStream != null){
> > > >                    try{
> > > >                        inputStream.close();
> > > >                    }catch(IOException e){
> > > >                        e.printStackTrace();
> > > >                    }
> > > >                }
> > > >            }
>
> > > > Please let me know how I can handle this problem. I used this post as
> > > > the reference while creating this.
>
> > > >http://senior.ceng.metu.edu.tr/2009/praeda/2009/01/11/a-simple-restfu.
> > ..
>
> > > > I tested the link in my browser and it does return the complete JSON.
> > > > So I am sure the issue is with my code in android.
>
> > > > Thank you.
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Android Developers" group.
> > > > To post to this group, send email to
> > android-developers@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > android-developers+unsubscribe@googlegroups.com<android-developers%2Bunsubscribe@googlegroups.com>
> > <android-developers%2Bunsubscribe@googlegroups.com<android-developers%252Bunsubscribe@googlegroups.com>
>
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/android-developers?hl=en
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscribe@googlegroups.com<android-developers%2Bunsubscribe@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment