Code example for File

Methods: lastModified, length

0
        if (alias == null) {
            throw new NullPointerException("alias == null");
        } 
        File file;
        if (isSystem(alias)) {
            file = new File(systemDir, alias.substring(PREFIX_SYSTEM.length()));
        } else if (isUser(alias)) {
            file = new File(addedDir, alias.substring(PREFIX_USER.length()));
        } else { 
            return null; 
        } 
        if (!file.exists() || isTombstone(file)) {
            // silently elide tombstones 
            return null; 
        } 
        return file;
    } 
 
    private boolean isTombstone(File file) {
        return file.length() == 0;
    } 
 
    private X509Certificate readCertificate(File file) {
        if (!file.isFile()) {
            return null; 
        } 
        InputStream is = null;
        try { 
            is = new BufferedInputStream(new FileInputStream(file));
            return (X509Certificate) CERT_FACTORY.generateCertificate(is);
        } catch (IOException e) {
            return null; 
        } catch (CertificateException e) {
            // reading a cert while its being installed can lead to this. 
            // just pretend like its not available yet. 
            return null; 
        } finally { 
            IoUtils.closeQuietly(is);
        } 
    } 
 
    private void writeCertificate(File file, X509Certificate cert)
            throws IOException, CertificateException { 
        File dir = file.getParentFile();
        dir.mkdirs();
        dir.setReadable(true, false);
        dir.setExecutable(true, false);
        OutputStream os = null;
        try { 
            os = new FileOutputStream(file);
            os.write(cert.getEncoded());
        } finally { 
            IoUtils.closeQuietly(os);
        } 
        file.setReadable(true, false);
    } 
 
    private boolean isDeletedSystemCertificate(X509Certificate x) {
        return getCertificateFile(deletedDir, x).exists();
    } 
 
    public Date getCreationDate(String alias) {
        // containsAlias check ensures the later fileForAlias result 
        // was not a deleted system cert. 
        if (!containsAlias(alias)) {
            return null; 
        } 
        File file = fileForAlias(alias);
        if (file == null) {
            return null; 
        } 
        long time = file.lastModified();
        if (time == 0) {
            return null; 
        } 
        return new Date(time);
    }