{"id":31,"date":"2009-07-10T14:33:47","date_gmt":"2009-07-10T20:03:47","guid":{"rendered":"http:\/\/www.arjarapu.com\/wordpress\/?p=31"},"modified":"2009-10-19T21:15:18","modified_gmt":"2009-10-20T02:45:18","slug":"net-reverse-stream-reader","status":"publish","type":"post","link":"http:\/\/www.arjarapu.com\/wordpress\/2009\/07\/net-reverse-stream-reader\/","title":{"rendered":".NET Reverse Stream Reader"},"content":{"rendered":"<p>How to read file bottom up:<br \/>\nRead text file bottom up:<\/p>\n<p>When we process the flat files, most of the times we process it top to bottom. However, there might be only a few times situation come where you you have to read bottom up. Like the other day, I have huge flat file about 250 MB and I need some information could be located anywhere in last 50 lines. Since length, size and # of lines I might have to look into in such files vary, reading top to bottom isn&#8217;t an optimal solution. <!--more--><\/p>\n<p>I came across couple of solutions like <a href=\"http:\/\/www.daniweb.com\/forums\/thread76696.html#\" title='Use an ArrayList, then iterate backwards'>Use an ArrayList, then iterate backwards<\/a>. This solution gets the stuff working but makes you read the whole file, store the data in memory and iterate in backwards. Hence it won&#8217;t fit my needs as my files are real big and cannot afford the memory to hold 250 MB file contents for reading just 50 lines from the end of file.<\/p>\n<p>So, I started writing my own C#.NET class, Arjarapu.IO.ReverseStreamReader,  to read a file from bottom up or read a file in reverse order. ReverseStreamReader extends StreamReader and supports the following methods limited only to ASCII based flat files.<\/p>\n<ul>\n<ol>Read <\/ol>\n<ol>Read (to buffer)<\/ol>\n<ol>ReadLine<\/ol>\n<ol>ReadToEnd<\/ol>\n<\/ul>\n<p>You may download the source in <a href='http:\/\/www.arjarapu.com\/wordpress\/wp-content\/uploads\/2011\/12\/reversestreamreader.zip'>here<\/a>. If you have any suggestions to support UNICODE and other encoded files or optimized version of this file, please comment in here.<\/p>\n<p>&#8211; Shyam Arjarapu<\/p>\n<p>Keywords: StreamReader, reverse, .NET, Stream Reader, Bottom up, Read a file backwards<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mostly we read files top to bottom. Should situation occurs that you have to read the file bottom to top, having StreamReader in Reverse Order would greatly help to get things done in optimized way. Since there aren&#8217;t any built in class available in .NET, I wrote a code in C#.NET to full fill my requirement. It support StreamReader methods like Read, Read (to buffer), ReadLine, ReadToEnd but are limited to work only on ASCII flat files.<\/p>\n<p><!--more--> <a href=\"http:\/\/www.arjarapu.com\/wordpress\/2009\/07\/net-reverse-stream-reader\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[18,24,17],"_links":{"self":[{"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/posts\/31"}],"collection":[{"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=31"}],"version-history":[{"count":9,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":118,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/posts\/31\/revisions\/118"}],"wp:attachment":[{"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.arjarapu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}