Note that there are some explanatory texts on larger screens.

plurals
  1. POReading RSS feed, end of reader before end of data
    primarykey
    data
    text
    <p>I'm coding this in Java for an Android device. I'd just like to read all of the data in the RSS feed and then I have a parser ready to act on the data. The trouble I'm getting is that only a small portion of the data is ever being read by my code. It then says the end of the reader has been reached and proceeds to return the partial data to the parser.</p> <p>The code I have is this:</p> <pre><code>try { URL contentUrl = new URL(url); URLConnection conn = contentUrl.openConnection(); HttpURLConnection httpConn = (HttpURLConnection) conn; httpConn.setAllowUserInteraction(false); httpConn.setInstanceFollowRedirects(true); httpConn.setRequestMethod("GET"); httpConn.connect(); if(httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) { InputStreamReader inStr = new InputStreamReader(httpConn.getInputStream()); int charsRead; char[] buff = new char[BUFFER_SIZE]; String data = ""; while((charsRead = inStr.read(buff,0,BUFFER_SIZE))!= -1) { data += String.copyValueOf(buff, 0, charsRead); buff = new char[BUFFER_SIZE]; } Log.d("Http","Data: "+data.); return data; } else { return null; } } catch(IOException e) { return null; } </code></pre> <p>The debug log output looks like this:</p> <pre><code>&gt; D/dalvikvm(19134): GC_FOR_MALLOC freed 24 objects / 757272 bytes in 27ms D/dalvikvm(19134): GC_FOR_MALLOC freed 2 objects / 48 bytes in 26ms D/dalvikvm(19134): GC_FOR_MALLOC freed 3 objects / 301112 bytes in 29ms I/dalvikvm-heap(19134): Grow heap (frag case) to 3.677MB for 305028-byte allocation D/dalvikvm(19134): GC_FOR_MALLOC freed 0 objects / 0 bytes in 37ms D/dalvikvm(19134): GC_FOR_MALLOC freed 10 objects / 760856 bytes in 27ms D/dalvikvm(19134): GC_FOR_MALLOC freed 3 objects / 305112 bytes in 26ms D/dalvikvm(19134): GC_FOR_MALLOC freed 10 objects / 770856 bytes in 26ms D/dalvikvm(19134): GC_FOR_MALLOC freed 2 objects / 48 bytes in 26ms D/dalvikvm(19134): GC_FOR_MALLOC freed 3 objects / 309112 bytes in 27ms D/dalvikvm(19134): GC_FOR_MALLOC freed 22 objects / 777648 bytes in 27ms D/dalvikvm(19134): GC_FOR_MALLOC freed 2 objects / 48 bytes in 30ms D/dalvikvm(19134): GC_FOR_MALLOC freed 3 objects / 309288 bytes in 26ms D/dalvikvm(19134): GC_FOR_MALLOC freed 27 objects / 778696 bytes in 27ms D/Http (19134): Data: &lt;?xml version="1.0" encoding="UTF-8"?&gt; D/Http (19134): &lt;?xml-stylesheet type="text/xsl" media="screen" href="/~d/sty les/atom10full.xsl"?&gt;&lt;?xml-stylesheet type="text/css" media="screen" href="http: //feeds.feedburner.com/~d/styles/itemcontent.css"?&gt;&lt;feed xmlns="http://www.w3.or g/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:geors s="http://www.georss.org/georss" xmlns:thr="http://purl.org/syndication/thread/1 .0" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssname space.org/feedburner/ext/1.0" gd:etag="W/&amp;quot;CUcFSHc7fip7ImA9Wx5UFk8.&amp;quot;"&gt;&lt; id&gt;tag:blogger.com,1999:blog-11300808&lt;/id&gt;&lt;updated&gt;2010-10-20T18:03:39.906-07:00 &lt;/updated&gt;&lt;title type="text"&gt;Google Code Blog&lt;/title&gt;&lt;subtitle type="html"&gt;Updat es from Google's open source projects.&lt;/subtitle&gt;&lt;link rel="http://schemas.googl e.com/g/2005#feed" type="application/atom+xml" href="http://googlecode.blogspot. com/feeds/posts/default" /&gt;&lt;link rel="alternate" type="text/html" href="http://g ooglecode.blogspot.com/" /&gt;&lt;link rel="next" type="application/atom+xml" href="ht tp://www.blogger.com/feeds/11300808/posts/default?start-index=26&amp;amp;max-results =25&amp;amp;redirect=false&amp;amp;v=2" /&gt;&lt;author&gt;&lt;name&gt;Chris DiBona&lt;/name&gt;&lt;email&gt;norepl y@blogger.com&lt;/email&gt;&lt;/author&gt;&lt;generator version="7.00" uri="http://www.blogger. com"&gt;Blogger&lt;/generator&gt;&lt;openSearch:totalResults&gt;753&lt;/openSearch:totalResults&gt;&lt;o penSearch:startIndex&gt;1&lt;/openSearch:startIndex&gt;&lt;openSearch:itemsPerPage&gt;25&lt;/openS earch:itemsPerPage&gt;&lt;atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel=" self" type="application/atom+xml" href="http://feeds.feedburner.com/blogspot/Dcn i" /&gt;&lt;feedburner:info uri="blogspot/dcni" /&gt;&lt;atom10:link xmlns:atom10="http://ww w.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /&gt;&lt;entry g d:etag="W/&amp;quot;CUcFSHc6fCp7ImA9Wx5UFk8.&amp;quot;"&gt;&lt;id&gt;tag:blogger.com,1999:blog-11 300808.post-3825033765857847156&lt;/id&gt;&lt;published&gt;2010-10-20T18:03:00.000-07:00&lt;/pu blished&gt;&lt;updated&gt;2010-10-20T18:03:39.914-07:00&lt;/updated&gt;&lt;app:edited xmlns:app="h ttp://www.w3.org/2007/app"&gt;2010-10-20T18:03:39.914-07:00&lt;/app:edited&gt;&lt;category s cheme="http://www.blogger.com/atom/ns#" term="speed tracer" /&gt;&lt;category scheme=" http://www.blogger.com/atom/ns#" term="gwt" /&gt;&lt;category scheme="http://www.blogg er.com/atom/ns#" term="eclipse" /&gt;&lt;category scheme="http://www.blogger.com/atom/ ns#" term="cloud portability" /&gt;&lt;title&gt;Advancing cloud computing with integrated developer tools by Google and VMware&lt;/title&gt;&lt;content type="html"&gt;&amp;lt;p&amp;gt;&amp;lt;i &amp;gt;Cross-posted from the &amp;lt;a href="http://googlewebtoolkit.blogspot.com/"&amp;gt; Google Web Toolkit Blog&amp;lt;/a&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/p&amp;gt; D/Http (19134): D/Http (19134): &amp;lt;p&amp;gt; D/Http (19134): Earlier this year at Google I/O, we &amp;lt;a href="http://google code.blogspot.com/2010/05/enabling-cloud-portability-with-google.html"&amp;gt;announ ced&amp;lt;/a&amp;gt; a collaboration between &amp;lt;a href="http://www.google.com"&amp;gt;Goog le&amp;lt;/a&amp;gt; and &amp;lt;a href="http://www.vmware.com"&amp;gt;VMware&amp;lt;/a&amp;gt; focused on making it easy to build business-oriented, &amp;lt;a href="http://code.google.com /cloudportability/"&amp;gt;cloud portable&amp;lt;/a&amp;gt; web apps. We showed how business es could use our integrated developer tools to build modern web apps that are ÔÇ £cloud readyÔÇØ from the start, and can be deployed to any standard environment, including &amp;lt;a href="http://code.google.com/appengine/"&amp;gt;Google App Engine&amp;l t;/a&amp;gt; and on &amp;lt;a href="http://www.springsource.com/products/cloud-applicati on-platform"&amp;gt;VMware vFabric&amp;lt;/a&amp;gt; on-premise solutions. Today we are happ y to announce that these tools will be generally available within the next few w eeks. D/Http (19134): &amp;lt;/p&amp;gt; D/Http (19134): D/Http (19134): &amp;lt;p&amp;gt; D/Http (19134): Of course, if youÔÇÖre itching to get a head start, you can j ump right in by downloading the release candidate version of &amp;lt;a href="http:// www.springsource.com/landing/best-development-tool-enterprise-java"&amp;gt;SpringSou rce Tool Suite&amp;lt;/a&amp;gt;. D/Http (19134): &amp;lt;/p&amp;gt; D/Http (19134): D/Http (19134): &amp;lt;p&amp;gt; D/Http (19134): If youÔÇÖd prefer to wait for the general release, you can &amp;l t;a href="http://code.google.com/cloudportability/"&amp;gt;sign up&amp;lt;/a&amp;gt; to be n otified as soon as they are </code></pre> <p>If you check the feed (http://feeds2.feedburner.com/blogspot/Dcni) then you'll see that this is only a tiny fraction of the content. I thought since I'm getting the heap message that the phone may be running out of heap space and therefore quitting, but I found an RSS TTS project which has its own http code: <a href="http://code.google.com/p/talkingrssreader/source/browse/trunk/talkingrss/src/com/googlecode/talkingrssreader/talkingrss/ReaderHttp.java" rel="nofollow">talkingrssreader</a> and when I pull theirs out and try it with my code it still has the same issue. Trying the talking RSS reader app with that feed doesn't have this issue.</p> <p>I'm at a loss now as to what else to try. I can obtain and parse shorter RSS feeds without a problem but it seems after a certain length it just refuses to gather all the data. I've gone through a lot of RSS readers in the Android market and not seen any others cut the feed short, so that makes me believe it's an issue in my code and not the device running out of memory. This is further evidenced by the fact that my code will easily read a 119kb xml file, but will fail on the Google RSS feed, which is only 32kb.</p> <p>Can anyone give me some ideas on what the issue could be?</p> <p>edit: After adding the changes suggested by the100rabh and Isaac, the code now looks like this:</p> <pre><code>InputStreamReader inStr = new InputStreamReader(httpConn.getInputStream()); int charsRead; char[] buff = new char[BUFFER_SIZE]; StringBuffer data = new StringBuffer(); while((charsRead = inStr.read(buff,0,BUFFER_SIZE))!= -1) { data.append(buff, 0, charsRead); } Log.d("Http","Data: "+data.toString()); return data.toString(); </code></pre> <p>The problem is still there though. It cuts the data short in exactly the same place as it did with the previous code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload