Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4107821
Votes 0
Synopsis BufferedReader.readLine(int maxlen) to limit maximum number of read characters
Category java:classes_io
Reported Against 1.1.5
Release Fixed
State 11-Closed, Will Not Fix, request for enhancement
Priority: 5-Very Low
Related Bugs
Submit Date 29-JAN-1998
Description



(company -  xxxxx  , email - lunn_r@mtn.co.za)

This would allow a programmer to read a line of text
not more than a certain number of characters.

Eg. reading a socket that does text IO (like SMTP)
one wants to read a line but not more than a certain
number of characters.

To use readLine() as is would be convinient but opens
such a socket reader to denial of service attacks
when a client spams volumes of text to the socket
with no new line characters.  The BufferedReader
will read all of the text and eventually run out
of memory.

(Review ID: 24018)
======================================================================
Posted Date : 2006-02-01 08:45:49.0
Work Around


public String readLine(int len)
{
  int currentPos=0;
  char[] data=new char[len]
  char newLineChar=System.getproperty("line.separator");
  char currentChar=read();

  while((currentChar != newLineChar) && (currentPos<len))
  {
    data[currentPos++]=currentChar;
    currentChar=read();
  }

  if(currentChar==newLineChar)
    return(new String(data,0,currentPos-1));
  else
    return(new String(data,0,currentPos));
}
======================================================================
Evaluation
This bug was submitted over 8 years ago.  Without any compelling use case or interest, there is no strong motivation to add an api which can be implemented in a few lines of code by the small set of users who require this funtionality.  Closing this request as "will not fix".
Posted Date : 2006-02-01 08:45:49.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang