On Wed, Mar 7, 2018 at 4:01 AM, sebb <seb...@gmail.com> wrote: > On 7 March 2018 at 04:24, Gary Gregory <garydgreg...@gmail.com> wrote: > > On Tue, Mar 6, 2018 at 4:32 PM, sebb <seb...@gmail.com> wrote: > > > >> On 6 March 2018 at 23:22, Gary Gregory <garydgreg...@gmail.com> wrote: > >> > On Tue, Mar 6, 2018 at 4:13 PM, sebb <seb...@gmail.com> wrote: > >> > > >> >> On 6 March 2018 at 21:38, Gary Gregory <garydgreg...@gmail.com> > wrote: > >> >> > Hi All: > >> >> > > >> >> > Any objection to adding: > >> >> > > >> >> > /** > >> >> > * Reads n lines from this reader. > >> >> > */ > >> >> > List<String> > >> >> > org.apache.commons.io.input.ReversedLinesFileReader.readLine(long > >> >> lineCount) > >> >> > > >> >> > ? > >> >> > >> >> Yes. > >> >> > >> >> The name makes it sound like it is reading a single line, yet the > >> >> output is a list of lines. > >> >> > >> > > >> > Cut and paste error, obviously, the method should be called > >> "readLines(long > >> > lineCount)" > >> > > >> > > >> >> Also, this seems like the sort of function that could be dealt with > >> >> via a more general approach which would work with any method. > >> >> AFAICT there would be no gain in embedding the looping code in IO > >> >> rather than having it somewhere else. > >> >> > >> > > >> > The gain is that your questions below would be defined by the new > method. > >> > >> As they would by an independent method. > >> > >> > > >> >> What happens if there aren't enough lines in the file? > >> >> > >> > > >> > If you ask for 30 lines, and there are only 10 lines, you get 10 > lines. > >> I'm > >> > not sure what else could happen, you can't invent data that does not > >> exist. > >> > > >> > What happens if there is an IO error reading one of the lines? > >> >> > >> > > >> > Then the method throws an exception, just like readLine() does. > >> > >> So all the lines that have already been read are lost? > >> > > > > Yes, just like all of the characters are lost when an exception is thrown > > when you call readLine() today. Nothing shocking there IMO. > > So basically it is a simple loop around readLine(). Or is there some > reason why it has to be part of IO? > > The method increases the cost of maintenance and the code size for > something that is easy to code externally. > > Also, I'm not sure that the potential number of use cases warrants > creating the code. >
To me, this is the kind of boilerplate I want to avoid rewriting, and is similar in spirit to org.apache.commons.io.IOUtils.readLines(Reader), which is basically a loop. More specifically, the class ReversedLinesFileReader is documented to be useful for log handling, which is what I am using it for. Like when I use the tail command, I never want to process the whole file; "Just show me then end N lines". Gary > > > Gary > > > > > >> > >> > Would you > >> > ask this question of readLine(): What happens if reading a single > >> character > >> > or a buffer of character causes an IO error? > >> > > >> > Gary > >> > > >> > > >> >> > >> >> > Gary > >> >> > >> >> ------------------------------------------------------------ > --------- > >> >> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > >> >> For additional commands, e-mail: dev-h...@commons.apache.org > >> >> > >> >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > >> For additional commands, e-mail: dev-h...@commons.apache.org > >> > >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > >