private Journal readJournal(ParcelFileDescriptor oldState){
  Journal journal=new Journal();
  if (oldState == null) {
    return journal;
  }
  FileInputStream inStream=new FileInputStream(oldState.getFileDescriptor());
  try {
    int availableBytes=inStream.available();
    if (DEBUG)     Log.d(TAG,"available " + availableBytes);
    if (availableBytes < MAX_JOURNAL_SIZE) {
      byte[] buffer=new byte[availableBytes];
      int bytesRead=0;
      boolean valid=false;
      InvalidProtocolBufferNanoException lastProtoException=null;
      while (availableBytes > 0) {
        try {
          int result=inStream.read(buffer,bytesRead,1);
          if (result > 0) {
            availableBytes-=result;
            bytesRead+=result;
          }
 else {
            Log.w(TAG,"unexpected end of file while reading journal.");
            availableBytes=0;
          }
        }
 catch (        IOException e) {
          buffer=null;
          availableBytes=0;
        }
        try {
          MessageNano.mergeFrom(journal,readCheckedBytes(buffer,bytesRead));
          valid=true;
          availableBytes=0;
          if (VERBOSE)           Log.v(TAG,"read " + bytesRead + " bytes of journal");
        }
 catch (        InvalidProtocolBufferNanoException e) {
          lastProtoException=e;
          journal.clear();
        }
      }
      if (DEBUG)       Log.d(TAG,"journal bytes read: " + bytesRead);
      if (!valid) {
        Log.w(TAG,"could not find a valid journal",lastProtoException);
      }
    }
  }
 catch (  IOException e) {
    Log.w(TAG,"failed to close the journal",e);
  }
  return journal;
}

private Journal readJournal ( ParcelFileDescriptor oldState ) { Journal journal = new Journal ( ) ; if ( oldState == null ) { return journal ; } FileInputStream inStream = new FileInputStream ( oldState . getFileDescriptor ( ) ) ; try { int availableBytes = inStream . available ( ) ; if ( DEBUG ) Log . d ( TAG , "available " + availableBytes ) ; if ( availableBytes < MAX_JOURNAL_SIZE ) { byte [ ] buffer = new byte [ availableBytes ] ; int bytesRead = 0 ; boolean valid = false ; InvalidProtocolBufferNanoException lastProtoException = null ; while ( availableBytes > 0 ) { try { int result = inStream . read ( buffer , bytesRead , 1 ) ; if ( result > 0 ) { availableBytes -= result ; bytesRead += result ; } else { Log . w ( TAG , "unexpected end of file while reading journal." ) ; availableBytes = 0 ; } } catch ( IOException e ) { buffer = null ; availableBytes = 0 ; } try { MessageNano . mergeFrom ( journal , readCheckedBytes ( buffer , bytesRead ) ) ; valid = true ; availableBytes = 0 ; if ( VERBOSE ) Log . v ( TAG , "read " + bytesRead + " bytes of journal" ) ; } catch ( InvalidProtocolBufferNanoException e ) { lastProtoException = e ; journal . clear ( ) ; } } if ( DEBUG ) Log . d ( TAG , "journal bytes read: " + bytesRead ) ; if ( ! valid ) { Log . w ( TAG , "could not find a valid journal" , lastProtoException ) ; } } } catch ( IOException e ) { Log . w ( TAG , "failed to close the journal" , e ) ; } return journal ; }
read the old journal from the input file . in the event of any error , just pretend we didn ' t have a journal , in that case , do a full backup .
