public synchronized Vector recover () throws LogException
{
if ( corrupt_ )
throw new LogException ( "Instance might be corrupted" );
Stack errors = new Stack ();
Vector ret = new Vector ();
InputStream in = null;
try {
FileInputStream f = file_.openLastValidVersionForReading();
in = f;
ObjectInputStream ins = new ObjectInputStream ( in );
int count = 0;
if ( console_ != null ) {
console_.println ( "Starting read of logfile " + file_.getCurrentVersionFileName() );
}
while ( in.available () > 0 ) {
// if crashed, then unproper closing might cause endless
// blocking!
// therefore, we check if avaible first.
count++;
Object nxt = ins.readObject ();
ret.addElement ( nxt );
if ( count % 10 == 0 ) {
if ( console_ != null )
console_.print ( "." );
}
}
if ( console_ != null ) {
console_.println ( "Done read of logfile" );
}
} catch ( java.io.EOFException unexpectedEOF ) {
// ignore, since this happens if log was not closed properly
// due to crash
// merely return what was read so far...
} catch ( StreamCorruptedException unexpectedEOF ) {
// ignore, since this happens if log was not closed properly
// due to crash
// merely return what was read so far...
} catch ( ObjectStreamException unexpectedEOF ) {
// ignore, since this happens if log was not closed properly
// due to crash
// merely return what was read so far...
} catch ( FileNotFoundException firstStart ) {
// the file could not be opened for reading;
// merely return the default empty vector
} catch ( Exception e ) {
System.err.println ( e.getMessage () );
System.err.println ( e.getClass ().getName () );
e.printStackTrace ();
errors.push ( e );
throw new LogException ( "Error in recover", errors );
} finally {
try {
if ( in != null )
in.close ();
} catch ( IOException io ) {
errors.push ( io );
throw new LogException ( "Error in recover", errors );
}
}
return ret;
}