FileDocCategorySizeDatePackage
RawDocumentFile.javaAPI DocAndroid 5.1 API4644Thu Mar 12 22:22:56 GMT 2015android.support.v4.provider

RawDocumentFile

public class RawDocumentFile extends DocumentFile

Fields Summary
private File
mFile
Constructors Summary
RawDocumentFile(DocumentFile parent, File file)

        super(parent);
        mFile = file;
    
Methods Summary
public booleancanRead()

        return mFile.canRead();
    
public booleancanWrite()

        return mFile.canWrite();
    
public DocumentFilecreateDirectory(java.lang.String displayName)

        final File target = new File(mFile, displayName);
        if (target.isDirectory() || target.mkdir()) {
            return new RawDocumentFile(this, target);
        } else {
            return null;
        }
    
public DocumentFilecreateFile(java.lang.String mimeType, java.lang.String displayName)

        // Tack on extension when valid MIME type provided
        final String extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType);
        if (extension != null) {
            displayName += "." + extension;
        }
        final File target = new File(mFile, displayName);
        try {
            target.createNewFile();
            return new RawDocumentFile(this, target);
        } catch (IOException e) {
            Log.w(TAG, "Failed to createFile: " + e);
            return null;
        }
    
public booleandelete()

        deleteContents(mFile);
        return mFile.delete();
    
private static booleandeleteContents(java.io.File dir)

        File[] files = dir.listFiles();
        boolean success = true;
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    success &= deleteContents(file);
                }
                if (!file.delete()) {
                    Log.w(TAG, "Failed to delete " + file);
                    success = false;
                }
            }
        }
        return success;
    
public booleanexists()

        return mFile.exists();
    
public java.lang.StringgetName()

        return mFile.getName();
    
public java.lang.StringgetType()

        if (mFile.isDirectory()) {
            return null;
        } else {
            return getTypeForName(mFile.getName());
        }
    
private static java.lang.StringgetTypeForName(java.lang.String name)

        final int lastDot = name.lastIndexOf('.");
        if (lastDot >= 0) {
            final String extension = name.substring(lastDot + 1).toLowerCase();
            final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
            if (mime != null) {
                return mime;
            }
        }

        return "application/octet-stream";
    
public android.net.UrigetUri()

        return Uri.fromFile(mFile);
    
public booleanisDirectory()

        return mFile.isDirectory();
    
public booleanisFile()

        return mFile.isFile();
    
public longlastModified()

        return mFile.lastModified();
    
public longlength()

        return mFile.length();
    
public DocumentFile[]listFiles()

        final ArrayList<DocumentFile> results = new ArrayList<DocumentFile>();
        final File[] files = mFile.listFiles();
        if (files != null) {
            for (File file : files) {
                results.add(new RawDocumentFile(this, file));
            }
        }
        return results.toArray(new DocumentFile[results.size()]);
    
public booleanrenameTo(java.lang.String displayName)

        final File target = new File(mFile.getParentFile(), displayName);
        if (mFile.renameTo(target)) {
            mFile = target;
            return true;
        } else {
            return false;
        }