• Post Reply Bookmark Topic Watch Topic
  • New Topic

Read bufferedreader character wise  RSS feed

 
Zack Mathew
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please explain what this code means?


I am particularly confused with the below lines -


This is how I am calling this code from my application -
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That method reads characters from a reader, upto a maximum of limit characters, and then returns a string containing the characters; it also stops reading whenever it finds a line feed ('\n') or carriage return ('\r') character.

The particular line means: if c is a line feed or carriage return character, then break out of the loop.

If the third part is literally how you call it in your application, then you will get a NullPointerException, because bf is null and you pass that as the reader; you would get a NullPointerException in line 5 of the readBuffer method, because reader will be null there.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zack Mathew wrote:I am particularly confused with the below lines -

Basically, it causes the method to ignore line-breaks, but it does it rather basically.

There are three common types of line-break, all based on legacy printers known as line printers: '\n' (a newline or 'line-feed'; used in Unix), '\r' (a carriage-return; used on older Mac systems), and '\r\n' (a CRLF; used by Windows, just to be different); there are even older formats that used LFCR, but they all use combinations of the two basic characters.

The problem with your method is that if it encounters a CRLF, it will return a line and then an empty String on the next call. Unfortunately, without some more "smarts" there really isn't a simple way around it, but I thought you should be aware.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!