public void init(){
  int len=Constants.FILE_BLOCK_SIZE;
  byte[] salt;
  byte[] magic=HEADER.getBytes(Constants.UTF8);
  if (length() < HEADER_LENGTH) {
    checkedWriting=false;
    writeDirect(magic,0,len);
    salt=generateSalt();
    writeDirect(salt,0,len);
    initKey(salt);
    write(magic,0,len);
    checkedWriting=true;
  }
 else {
    seek(0);
    byte[] buff=new byte[len];
    readFullyDirect(buff,0,len);
    if (!Arrays.equals(buff,magic)) {
      throw DbException.get(ErrorCode.FILE_VERSION_ERROR_1,name);
    }
    salt=new byte[len];
    readFullyDirect(salt,0,len);
    initKey(salt);
    readFully(buff,0,Constants.FILE_BLOCK_SIZE);
    if (!Arrays.equals(buff,magic)) {
      throw DbException.get(ErrorCode.FILE_ENCRYPTION_ERROR_1,name);
    }
  }
}

public void init ( ) { int len = Constants . FILE_BLOCK_SIZE ; byte [ ] salt ; byte [ ] magic = HEADER . getBytes ( Constants . UTF8 ) ; if ( length ( ) < HEADER_LENGTH ) { checkedWriting = false ; writeDirect ( magic , 0 , len ) ; salt = generateSalt ( ) ; writeDirect ( salt , 0 , len ) ; initKey ( salt ) ; write ( magic , 0 , len ) ; checkedWriting = true ; } else { seek ( 0 ) ; byte [ ] buff = new byte [ len ] ; readFullyDirect ( buff , 0 , len ) ; if ( ! Arrays . equals ( buff , magic ) ) { throw DbException . get ( ErrorCode . FILE_VERSION_ERROR_1 , name ) ; } salt = new byte [ len ] ; readFullyDirect ( salt , 0 , len ) ; initKey ( salt ) ; readFully ( buff , 0 , Constants . FILE_BLOCK_SIZE ) ; if ( ! Arrays . equals ( buff , magic ) ) { throw DbException . get ( ErrorCode . FILE_ENCRYPTION_ERROR_1 , name ) ; } } }
initialize the file . this method will write or check the file header if required .
