Code example for RandomAccessFile

Methods: close, length, read

0
            // Read all the bytes from the file 
            RandomAccessFile raf = new RandomAccessFile(getLockPatternFilename(userId), "r");
            final byte[] stored = new byte[(int) raf.length()];
            int got = raf.read(stored, 0, stored.length);
            raf.close();
            if (got <= 0) {
                return true; 
            } 
            // Compare the hash from the file with the entered pattern's hash 
            return Arrays.equals(stored, hash);
        } catch (FileNotFoundException fnfe) {
            Slog.e(TAG, "Cannot read file " + fnfe);
            return true; 
        } catch (IOException ioe) {
            Slog.e(TAG, "Cannot read file " + ioe);
            return true; 
        } 
    } 
 
    @Override 
    public void setLockPassword(byte[] hash, int userId) throws RemoteException {