Code example for RandomAccessFile

Methods: close, length, setLength

0
        assertTrue(message.contains(mCacheDir.getPath()));
        ApiLookup.dispose(); 
 
        mLogBuffer.setLength(0);
        assertTrue(cacheFile.exists());
        raf = new RandomAccessFile(cacheFile, "rw");
        // Truncate file in half in the data portion 
        raf.setLength(raf.length() / 2);
        raf.close();
        lookup = ApiLookup.get(new LookupTestClient());
        // This data is now truncated: lookup returns the wrong size. 
        try { 
            assertNotNull(lookup);
            lookup.getFieldVersion("android/R$attr", "actionMenuTextAppearance");
            fail("Can't look up bogus data"); 
        } catch (Throwable t) {
            // Expected this: the database is corrupted. 
        } 
        assertTrue(message.contains("Please delete the file and restart the IDE/lint:"));
        assertTrue(message.contains(mCacheDir.getPath()));
        ApiLookup.dispose();