Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

readLine(boolean)  RSS feed

 
Shobit Beltangdy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All!

I was reading the BufferedReader class source code and came across a function called readLine(boolean ignoreLF). When I saw the public readLine() function which we can use through an object of BufferedReader, I realized that readLine() calls the readLine(boolean ignoreLF) with a false parameter. I understood that this is the reason why readLine() cannot read two lines terminated by \n.

I'm wondering if it is possible to call the readLine(boolean) by sending it a true parameter (either directly or indirectly). I know I have other options (e.g. by using read()), but I just want to try it out using readLine(boolean)

Any help?

Thanks!

Regards,
Shobit

 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

If you looked at the source code, you saw that the method is not public; it has no access modifier and therefore has only package visibility. That means you cannot call it; the Javadoc page reflects this.
 
Shobit Beltangdy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

So is there no way that I can make the readLine() read a line and not terminate at the \n ?
E.g. for reading the Http Request in which the request-line and header are separated by \r\n?

(I'm just trying this as a challenge...I know there are other ways )
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know, if readLine() encounters an empty line (with only \r\n or \n), it will simply return an empty String.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!