private boolean isDatabaseHeaderValid ( SQLiteDatabase sqliteDatabase ) { boolean validHeader = false ; FileInputStream fis = null ; try { fis = new FileInputStream ( sqliteDatabase . getPath ( ) ) ; byte [ ] headerBytes = new byte [ 16 ] ; if ( fis . read ( headerBytes ) == 16 ) { ByteReader byteReader = new ByteReader ( headerBytes ) ; String header = byteReader . readString ( headerBytes . length ) ; String headerPrefix = header . substring ( 0 , GeoPackageConstants . SQLITE_HEADER_PREFIX . length ( ) ) ; validHeader = headerPrefix . equalsIgnoreCase ( GeoPackageConstants . SQLITE_HEADER_PREFIX ) ; } } catch ( Exception e ) { Log . e ( GeoPackageManagerImpl . class . getSimpleName ( ) , "Failed to retrieve database header" , e ) ; } finally { if ( fis != null ) { try { fis . close ( ) ; } catch ( IOException e ) { // eat } } } return validHeader ; }
Determine if the header of the database file is valid