public void recover() throws IOException {
  if (version == 0)   return;
  String fname=versionName(snapshotPrefix);
  File file=new File(fname);
  InputStream in=new BufferedInputStream(new FileInputStream(file));
  try {
    handler.recover(in);
  }
 catch (  Exception e) {
    throw new LogException("recovery failed",e);
  }
 finally {
    in.close();
  }
  snapshotBytes=file.length();
  fname=versionName(logfilePrefix);
  file=new File(fname);
  DataInputStream din=new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
  long length=file.length();
  try {
    int updateLen=din.readInt();
    if (updateLen == MAGIC) {
      format=din.readInt();
      if (format != FORMAT_PADDED) {
        throw new LogException("corrupted log: bad log format");
      }
      logBytes+=(intBytes + intBytes);
      updateLen=din.readInt();
    }
    while (true) {
      if (updateLen == 0) {
        break;
      }
      if (updateLen < 0) {
        throw new LogException("corrupted log: bad update length");
      }
      if (length - logBytes - intBytes < updateLen) {
        break;
      }
      try {
        handler.readUpdate(new LogInputStream(din,updateLen));
      }
 catch (      Exception e) {
        throw new LogException("read update failed",e);
      }
      logBytes+=(intBytes + updateLen);
      if (format == FORMAT_PADDED) {
        int offset=(int)logBytes & 3;
        if (offset > 0) {
          offset=4 - offset;
          logBytes+=offset;
          din.skipBytes(offset);
        }
      }
      updateLen=din.readInt();
    }
  }
 catch (  EOFException e) {
  }
 finally {
    din.close();
  }
  openLogFile();
}

public void recover ( ) throws IOException { if ( version == 0 ) return ; String fname = versionName ( snapshotPrefix ) ; File file = new File ( fname ) ; InputStream in = new BufferedInputStream ( new FileInputStream ( file ) ) ; try { handler . recover ( in ) ; } catch ( Exception e ) { throw new LogException ( "recovery failed" , e ) ; } finally { in . close ( ) ; } snapshotBytes = file . length ( ) ; fname = versionName ( logfilePrefix ) ; file = new File ( fname ) ; DataInputStream din = new DataInputStream ( new BufferedInputStream ( new FileInputStream ( file ) ) ) ; long length = file . length ( ) ; try { int updateLen = din . readInt ( ) ; if ( updateLen == MAGIC ) { format = din . readInt ( ) ; if ( format != FORMAT_PADDED ) { throw new LogException ( "corrupted log: bad log format" ) ; } logBytes += ( intBytes + intBytes ) ; updateLen = din . readInt ( ) ; } while ( true ) { if ( updateLen == 0 ) { break ; } if ( updateLen < 0 ) { throw new LogException ( "corrupted log: bad update length" ) ; } if ( length - logBytes - intBytes < updateLen ) { break ; } try { handler . readUpdate ( new LogInputStream ( din , updateLen ) ) ; } catch ( Exception e ) { throw new LogException ( "read update failed" , e ) ; } logBytes += ( intBytes + updateLen ) ; if ( format == FORMAT_PADDED ) { int offset = ( int ) logBytes & 3 ; if ( offset > 0 ) { offset = 4 - offset ; logBytes += offset ; din . skipBytes ( offset ) ; } } updateLen = din . readInt ( ) ; } } catch ( EOFException e ) { } finally { din . close ( ) ; } openLogFile ( ) ; }
retrieves the contents of the snapshot file by calling the client supplied recover callback and then applies the incremental updates by calling the readupdate callback for each logged updated .
