Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 59225979A for ; Fri, 4 Nov 2011 16:46:15 +0000 (UTC) Received: (qmail 15763 invoked by uid 500); 4 Nov 2011 16:46:14 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 15676 invoked by uid 500); 4 Nov 2011 16:46:14 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 15668 invoked by uid 99); 4 Nov 2011 16:46:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Nov 2011 16:46:14 +0000 X-ASF-Spam-Status: No, hits=-2001.2 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Nov 2011 16:46:12 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 7ECE630CBF8 for ; Fri, 4 Nov 2011 16:45:51 +0000 (UTC) Date: Fri, 4 Nov 2011 16:45:51 +0000 (UTC) From: "Georg Henzler (Updated) (JIRA)" To: issues@commons.apache.org Message-ID: <133804750.281.1320425151520.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1760327694.7810.1318970590858.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Updated] (IO-288) Supply a ReverseFileReader MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/IO-288?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Georg Henzler updated IO-288: ----------------------------- Attachment: ReversedLinesFileReader.zip Attached simple maven project with java class and unit tests. > Supply a ReverseFileReader > -------------------------- > > Key: IO-288 > URL: https://issues.apache.org/jira/browse/IO-288 > Project: Commons IO > Issue Type: New Feature > Components: Utilities > Reporter: Georg Henzler > Attachments: ReversedLinesFileReader.zip > > > I needed to analyse a log file today and I was looking for a ReverseFileReader: A class that behaves exactly like BufferedReader except that it goes from bottom to top when readLine() is called. I didn't find it in IOUtils and the internet didn't help a lot either, e.g. http://www.java2s.com/Tutorial/Java/0180__File/ReversingaFile.htm is a fairly inefficient - the log files I'm analysing are huge and it is not a good idea to load the whole content in the memory. > So I ended up writing an implementation myself using little memory and the class RandomAccessFile - see attached file. It's used as follows: > int blockSize = 4096; // only that much memory is needed, no matter how big the file is > ReverseFileReader reverseFileReader = new ReverseFileReader(myFile, blockSize, "UTF-8"); // encoding is supported > String line = null; > while((line=reverseFileReader.readLine())!=null) { > ... // use the line > if(enoughLinesSeen) { > break; > } > } > reverseFileReader.close(); > I believe this could be useful for other people as well! -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira