Currently I use readline() to get a line
and then I parse the resulting String (character by character)
to get the bits I want.

I then read the different parts into a class and return it
to a calling method which reads the class into a Vector and
returns the Vector.

This is the first method:

public static LoginLog[] readLog()throws FileNotFoundException
{
  Vector log = new Vector();

  try {
    FileReader inFile = new FileReader( "/var/log/GFWlogin.log" );
    BufferedReader bfFile = new BufferedReader( inFile );
      while ( bfFile.ready() ) {
        LoginLog logentry = getLogentry( bfFile );
        log.add( logentry );
      }
    bfFile.close();
   } catch ( IOException e ) {} ;
   return (LoginLog[])log.toArray( new LoginLog[log.size()] );
}


The method "getLogentry( bfFile )" simply reads the
line, parses the String and returns the class as I described
at the top.

Adam.



On Wed, 2004-03-10 at 13:15, Peter Guyatt wrote:
> Hi There,
> 
>       This read of the file? are you doing it a character at a time (ie via the
> read() method?)
> 
> If so try reading more than one charcter at a time.
> 
> Ie.
> 
> public void readFile (String filename) {
>       try {
>               File f = new File(filename);
>               FileReader fr = new FileReader(f);
>             char data[] = new char[4096];
>             int line = 0, read, i;
>               //loop until all the data is read from the stream
>             while ((read = fr.read(data, 0, 4096)) != -1) {
>                 //do somthing with the data read
>               }
>       } catch (Exception e) {
>               e.printStackTrace();
>       }
> }
> 
> This will dramatically improve performance and hopefully stop your problem
> 
> Thanks
> 
> Pete
> 
> -----Original Message-----
> From: Parsons Technical Services [mailto:[EMAIL PROTECTED]
> Sent: 10 March 2004 13:06
> To: Tomcat Users List
> Subject: Re: Tomcat 4.1 hangs on File Reading
> 
> 
> Adam,
> 
> Sound very similar to a problem I had a couple of days ago. Are you using
> any loops in your code? Specifically while or do-while or endless for loops.
> If so try changing them to a for loop with a high count say 10k-100k and see
> what happens. I had a sort method that under the right conditions would
> bring down my IDE and hog all the processor.
> 
> Doug
> www.parsonstechnical.com
> 
> ----- Original Message -----
> From: "Adam Buglass" <[EMAIL PROTECTED]>
> To: "Tomcat Users List" <[EMAIL PROTECTED]>
> Sent: Wednesday, March 10, 2004 7:52 AM
> Subject: Tomcat 4.1 hangs on File Reading
> 
> 
> > I've got a website which members can log in and out of
> > (by way of a form which connects to a JSP).
> >
> > I've created a simple method in a Java class to write to
> > a text format log file to tell me stuff like who they are,
> > when they logged in etc.
> >
> > So far so good.
> >
> > I'm now trying to write a JSP to analyse this log but
> > when I try and access the page, tomcat usually hangs
> > indefinitely. Occassionally it will display something I jtas ask
> > for, say, the Strings of IDs. Tomcat will then slow right down
> > (approximately 4-6x slower) and eventually need restarting.
> >
> > I've tried with a smaller test file.
> > I'm closing the file connection which I open in Java.
> > There doesn't appear to be anything in the logs, in fact
> > neither Tomcat nor Apache appear to recognise the page request
> > at all.
> >
> > Any ideas / thoughts / suggestions !?
> >
> > Thanks,
> > Adam.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
-- 

Adam Buglass,  ><>
The Golden Freeway,
Department of Child Health,
University of Newcastle-upon-Tyne.
Royal Victoria Infirmary.

(0191) 2023062

"Democracy is two wolves and a lamb voting on what to have for lunch.
Liberty is a well-armed lamb contesting the vote." 
~Benjamin Franklin, 1759


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to